-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.js
53 lines (47 loc) · 1.31 KB
/
User.js
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
const mongoose = require("mongoose")
const passportLocalMongoose = require('passport-local-mongoose');
const userSchema = new mongoose.Schema({
// username : { ---> this is automatically handled by passport-local-mongoose, no need to add on our own
// type : String ---> this is automatically handled by passport-local-mongoose
// },
// password : String,
email : {
type : String,
// required : true,
// unique : true
},
googleId: {
type: String,
default : null,
// unique : false
},
userType : {
type : String,
//predefined values
enum : ["consumer", "retailer"],
default : "consumer"
},
cart : [
{
name : String,
price : Number,
img : String,
//id of product
id : mongoose.Schema.Types.ObjectId,
count : {
type : Number,
default : 1,
min : [1, "Quantity cannot be less than 1"]
}
}
],
wishlist : [{
name : String,
price : Number,
img : String,
id : mongoose.Schema.Types.ObjectId
}]
})
userSchema.plugin(passportLocalMongoose);
const User = mongoose.model("User", userSchema);
module.exports = User;