Cart.js 846 Bytes
Newer Older
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
1
2
import mongoose from 'mongoose'

3
4
const { String, Number, Array, ObjectId } = mongoose.Schema.Types
const productschema = new mongoose.Schema ({
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
5
6
    pro_name: {
        type: String,
7
        required: true
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
8
    },
9
    price:{
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
10
11
12
        type: Number,
        required: true
    },
13
14
15
    main_image: {
        type: String,
        required: true
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
16
    },
17
    color:{
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
18
        type: String,
19
        required: true
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
20
    },
21
22
23
    size:{
        type: String,
        required: true
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
24
    },
25
26
27
28
29
30
31
    productObjectId: {
        type: ObjectId,
        required: true
    }
})
const CartSchema = new mongoose.Schema({
    userId: {
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
32
        type: String,
33
34
35
36
37
        // required: true
    },
    products : {
        type: [productschema],
        required: true
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
38
    }
39
   
Jiwon Yoon's avatar
22    
Jiwon Yoon committed
40
41
42
43
44
}, {
    timestamps: true
})

export default mongoose.models.Cart || mongoose.model('Cart', CartSchema)