This repository was archived by the owner on Apr 19, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +124
-0
lines changed
Expand file tree Collapse file tree 5 files changed +124
-0
lines changed Original file line number Diff line number Diff line change 1+ import {
2+ Entity ,
3+ PrimaryGeneratedColumn ,
4+ CreateDateColumn ,
5+ UpdateDateColumn ,
6+ Column
7+ } from "typeorm" ;
8+
9+ @Entity ( )
10+ export class BackupCode {
11+ @PrimaryGeneratedColumn ( "uuid" )
12+ code ! : number ;
13+
14+ @Column ( )
15+ userId ! : number ;
16+
17+ @Column ( )
18+ used ! : boolean ;
19+
20+ @CreateDateColumn ( )
21+ createdAt ! : Date ;
22+
23+ @UpdateDateColumn ( )
24+ updatedAt ! : Date ;
25+ }
Original file line number Diff line number Diff line change 1+ import {
2+ Entity ,
3+ PrimaryGeneratedColumn ,
4+ CreateDateColumn ,
5+ Column
6+ } from "typeorm" ;
7+ import { EventType } from "../interfaces/enum" ;
8+
9+ @Entity ( )
10+ export class Event {
11+ @PrimaryGeneratedColumn ( )
12+ id ! : number ;
13+
14+ @Column ( )
15+ userId ! : number ;
16+
17+ @Column ( {
18+ type : "enum" ,
19+ enum : EventType ,
20+ default : EventType . USER_CREATED
21+ } )
22+ type ! : EventType ;
23+
24+ @Column ( )
25+ data ?: string ;
26+
27+ @CreateDateColumn ( )
28+ createdAt ! : Date ;
29+ }
Original file line number Diff line number Diff line change 1+ import {
2+ Entity ,
3+ PrimaryGeneratedColumn ,
4+ CreateDateColumn ,
5+ UpdateDateColumn ,
6+ Column ,
7+ OneToOne ,
8+ JoinColumn ,
9+ ManyToOne
10+ } from "typeorm" ;
11+ import { UserRole } from "../interfaces/enum" ;
12+ import { User } from "./user" ;
13+ import { Organization } from "./organization" ;
14+
15+ @Entity ( )
16+ export class Membership {
17+ @PrimaryGeneratedColumn ( )
18+ id ! : number ;
19+
20+ @ManyToOne ( type => Organization )
21+ @JoinColumn ( )
22+ organization ! : Organization ;
23+
24+ @OneToOne ( type => User )
25+ @JoinColumn ( )
26+ user ! : User ;
27+
28+ @Column ( {
29+ type : "enum" ,
30+ enum : UserRole ,
31+ default : UserRole . ADMIN
32+ } )
33+ role ! : UserRole ;
34+
35+ @CreateDateColumn ( )
36+ createdAt ! : Date ;
37+
38+ @UpdateDateColumn ( )
39+ updatedAt ! : Date ;
40+ }
Original file line number Diff line number Diff line change 1+ export enum UserRole {
2+ ADMIN = "admin" ,
3+ MEMBER = "member"
4+ }
5+
6+ export enum EventType {
7+ USER_CREATED = "user.created" ,
8+ USER_UPDATED = "user.updated" ,
9+ USER_DELETED = "user.deleted" ,
10+ AUTH_LOGIN = "auth.login" ,
11+ AUTH_LOGIN_BACKUP_CODE = "auth.login_backupCode" ,
12+ AUTH_LOGIN_GOOGLE = "auth.login_google" ,
13+ AUTH_PASSWORD_CHANGED = "auth.password_changed" ,
14+ ORGANIZATION_CREATED = "organization.created" ,
15+ ORGANIZATION_UPDATED = "organization.updated" ,
16+ ORGANIZATION_DELETED = "organization.deleted"
17+ }
Original file line number Diff line number Diff line change 1+ import { connect } from "../helpers/database" ;
2+ import { User } from "../entities/user" ;
3+
4+ export const create = async ( user : User ) => {
5+ const connection = await connect ( ) ;
6+ await connection
7+ . createQueryBuilder ( )
8+ . insert ( )
9+ . into ( User )
10+ . values ( user )
11+ . execute ( ) ;
12+ connection . close ( ) ;
13+ } ;
You can’t perform that action at this time.
0 commit comments