code.js 936 B

12345678910111213141516171819202122
  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 code = {
  8. code: { type: String, required: true, maxLength: 500 }, // code
  9. name: { type: String, required: true, maxLength: 500 }, // 名称
  10. category: { type: String, required: true, maxLength: 500 }, // 类别code
  11. sort: { type: Number, required: false, maxLength: 500 }, // 排序
  12. remark: { type: String, maxLength: 200 },
  13. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  14. };
  15. const schema = new Schema(code, { toJSON: { virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.index({ 'meta.createdAt': 1 });
  18. schema.plugin(metaPlugin);
  19. module.exports = app => {
  20. const { mongoose } = app;
  21. return mongoose.model('Code', schema, 'code');
  22. };