File size: 1,522 Bytes
97f53b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const { Schema, model } = require("mongoose");
const mongoose = require("mongoose");

const hijabsScema = new Schema(
    {
        name: {
            type: String,
            required: true,
            unique: true,
            trim: true,
            minLength: [3, "Too Short product Name"],
        },
        images: {
            type: [String],
        },
        description: {
            type: String,
            maxlength: [100, "Description should be less than or equal to 100"],
            minlength: [10, "Description should be more than or equal to 10"],
            required: true,
            trim: true,
        },
        price: {
            type: Number,
            default: 0,
            min: 0,
            required: true,
        },
        priceAfterDiscount: {
            type: Number,
            default: 0,
            min: 0,
        },
        quantity: {
            type: Number,
            default: 0,
            min: 0,
        },
        sold: {
            type: Number,
            default: 0,
            min: 0,
        },
        category: {
            type: Schema.ObjectId,
            ref: "Category",
            required: true,
        },
        ratingAvg: {
            type: Number,
            min: 1,
            max: 5,
        },
        ratingCount: {
            type: Number,
            min: 0,
        },
    },
    { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
)

module.exports = mongoose.model('hijabs', hijabsScema);