User.js 883 Bytes
Newer Older
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
1
import mongoose from "mongoose";
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
2
3

const { String } = mongoose.Schema.Types
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
4
const { Array } = mongoose.Schema.Types
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
5

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
6
7
8
9
10
11
12
13
14
15
const { Schema } = mongoose;
const { Types: { ObjectId } } = Schema;
const ReserveSchema = new Schema({
  user: {
    type: ObjectId,
    required: true,
    ref: 'User',
  },
})

Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const UserSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true,
    },
    email: {
        type: String,
        required: true,
        unique: true,
    },
    password: {
        type: String,
        required: true,
        select: false,
    },
    role: {
        type: String,
        required: true,
        default: 'user',
        enum: ['user', 'admin', 'root']
    },
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
37
38
39
40
    bookmark: {
        type: Array,
        required: true,
    }
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
41
42
43
44
45
}, {
    timestamps: true
})

export default mongoose.models.User || mongoose.model('User', UserSchema)