-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
User.ts
96 lines (77 loc) · 1.9 KB
/
User.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import "reflect-metadata";
import { Room } from "./Room";
import { ObjectID } from "mongodb";
import { Field, ObjectType } from "type-graphql";
import {
prop as Property,
Ref,
arrayProp,
getModelForClass,
modelOptions,
} from "@typegoose/typegoose";
enum Providers {
GOOGLE = "google",
GITHUB = "github",
}
@ObjectType()
@modelOptions({ schemaOptions: { _id: false } })
export class UserLinks {
@Field({ nullable: true })
@Property({ minlength: 5, maxlength: 100 })
public github?: string;
@Field({ nullable: true })
@Property({ minlength: 5, maxlength: 100 })
public twitter?: string;
@Field({ nullable: true })
@Property({ minlength: 5, maxlength: 100 })
public instagram?: string;
@Field({ nullable: true })
@Property({ minlength: 5, maxlength: 100 })
public website?: string;
}
@modelOptions({
options: { customName: "user" },
schemaOptions: {
timestamps: true,
collection: "users",
},
})
@ObjectType()
export class User {
@Field(type => ObjectID, { name: "id" })
_id: ObjectID;
updatedAt!: Date;
@Field()
createdAt!: Date;
@Field()
@Property({ required: true })
public name!: string;
@Field()
@Property({
required: true,
trim: true,
minlength: 2,
maxlength: 100,
unique: true,
})
public username!: string;
@Field(type => [Room])
@arrayProp({ ref: "room" })
public rooms!: Ref<Room>[];
@Field()
@Property({ default: "#64FF8F" })
public color!: string;
@Field(type => UserLinks, { nullable: true })
@Property({ type: UserLinks, default: {} })
public links!: UserLinks;
@Property({ required: true, unique: true })
public email!: string;
@Property({ enum: Providers })
public provider!: string;
@Property({ required: true, unique: true })
public socialId!: string;
@Property({ required: true })
public avatarUrl!: string;
}
const UserModel = getModelForClass(User);
export default UserModel;