-
Notifications
You must be signed in to change notification settings - Fork 312
/
Product.js
83 lines (82 loc) · 1.77 KB
/
Product.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import mongoose from 'mongoose'
import basePlugin from './base_model'
const ProductSchema = new mongoose.Schema(
{
title: {
type: String,
required: true,
},
price: {
type: Number,
required: true,
},
description: {
type: String,
},
discount: { type: Number, default: 0 },
images: [
{
url: {
type: String,
required: true,
},
},
],
sizes: [
{
id: { type: String, required: true },
size: { type: String, required: true },
},
],
colors: [
{
id: { type: String, required: true },
name: { type: String, required: true },
hashCode: { type: String, required: true },
},
],
category: [{ type: String, required: true }],
category_levels: {
level_one: {
type: mongoose.Types.ObjectId,
ref: 'category',
},
level_two: {
type: mongoose.Types.ObjectId,
ref: 'category',
},
Level_three: {
type: mongoose.Types.ObjectId,
ref: 'category',
},
},
inStock: {
type: Number,
default: 0,
},
sold: {
type: Number,
default: 0,
},
info: [
{
title: { type: String, required: true },
value: { type: String, required: false },
},
],
specification: [
{
title: { type: String, required: true },
value: { type: String, required: false },
},
],
rating: { type: Number, required: true, default: 0 },
numReviews: { type: Number, required: true, default: 0 },
},
{
timestamps: true,
}
)
ProductSchema.plugin(basePlugin)
const Product = mongoose.models.product || mongoose.model('product', ProductSchema)
export default Product