product.js 773 B

123456789101112131415161718192021
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. // 产品表
  5. const product = {
  6. name: { type: String, required: true, maxLength: 200 }, // 名称
  7. filepath: { type: String, required: false, maxLength: 200 }, // 图片路径
  8. create_time: { type: String, required: false, maxLength: 200 }, // 发布时间
  9. content: { type: String, required: false, maxLength: 500 }, // 内容
  10. brief: { type: String, required: false, maxLength: 500 }, // 简介
  11. };
  12. const schema = new Schema(product, { toJSON: { virtuals: true } });
  13. schema.index({ id: 1 });
  14. schema.plugin(metaPlugin);
  15. module.exports = app => {
  16. const { mongoose } = app;
  17. return mongoose.model('Product', schema, 'product');
  18. };