Explorar o código

스키마 생성

허용운 %!s(int64=5) %!d(string=hai) anos
pai
achega
c9d9503041
Modificáronse 3 ficheiros con 33 adicións e 0 borrados
  1. 8 0
      models/category.js
  2. 10 0
      models/owner.js
  3. 15 0
      models/product.js

+ 8 - 0
models/category.js

@@ -0,0 +1,8 @@
+const mongoose = require('mongoose')
+const Schema = mongoose.Schema
+
+const CategorySchema = new Schema({
+  type: { type:String, unique: true, required: true }
+})
+
+module.exports = mongoose.model('Category', CategorySchema)

+ 10 - 0
models/owner.js

@@ -0,0 +1,10 @@
+const mongoose = require('mongoose')
+const Schema = mongoose.Schema
+
+const OwnerSchema = new Schema({
+  title: String,
+  about: String,
+  photo: String
+})
+
+module.exports = mongoose.model('Owner', OwnerSchema)

+ 15 - 0
models/product.js

@@ -0,0 +1,15 @@
+const mongoose = require('mongoose')
+const Schema = mongoose.Schema
+
+const ProductSchema = new Schema({
+  category: { type:Schema.Types.ObjectId, ref: 'Category' },
+  owner: { type:Schema.Types.ObjectId, ref: 'Owner' },
+  title: String,
+  description: String,
+  photo: String,
+  price: Number,
+  stockQuantity: Number,
+  rating: [Number]
+})
+
+module.exports = mongoose.model('Product', ProductSchema)