Skip to content

Commit a35940f

Browse files
Creating User model
1 parent 1a06fc8 commit a35940f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/models/User.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { model, Schema, Document } from 'mongoose'
2+
3+
export interface IUser extends Document {
4+
displayName: string;
5+
username: string;
6+
email: string;
7+
password: string;
8+
avatar: string;
9+
role: string;
10+
status: boolean;
11+
}
12+
13+
const UserSchema = new Schema({
14+
displayName: {
15+
type: String,
16+
required: true
17+
},
18+
username: {
19+
type: String,
20+
minlength: 4,
21+
required: true
22+
},
23+
email: {
24+
type: String,
25+
unique: true,
26+
trim: true,
27+
lowercase: true,
28+
required: true
29+
},
30+
password: {
31+
type: String,
32+
minlength: 6,
33+
required: true
34+
},
35+
avatar: {
36+
type: String,
37+
maxlength: 512,
38+
required: false
39+
},
40+
role: {
41+
type: String,
42+
enum: ["SUPERADMIN","ADMIN","USER"],
43+
default: "USER"
44+
},
45+
status: {
46+
type: Boolean,
47+
default: true
48+
}
49+
},{
50+
timestamps: true
51+
})
52+
53+
export default model<IUser>('User', UserSchema)

0 commit comments

Comments
 (0)