浏览代码

스키마 생성

허용운 5 年之前
父节点
当前提交
c9d9503041
共有 3 个文件被更改,包括 33 次插入0 次删除
  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)