category.js 819 B

1234567891011121314151617181920
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. const { Secret } = require('naf-framework-mongoose/lib/model/schema');
  6. // 字典类别表
  7. const category = {
  8. code: { type: String, required: true, maxLength: 500 }, // 类别code
  9. name: { type: String, required: true, maxLength: 500 }, // 名称
  10. remark: { type: String, maxLength: 200 },
  11. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  12. };
  13. const schema = new Schema(category, { toJSON: { virtuals: true } });
  14. schema.index({ id: 1 });
  15. schema.index({ 'meta.createdAt': 1 });
  16. schema.plugin(metaPlugin);
  17. module.exports = app => {
  18. const { mongoose } = app;
  19. return mongoose.model('Category', schema, 'category');
  20. };