dictionary.js 780 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. const { Secret } = require('naf-framework-mongoose/lib/model/schema');
  5. // 字典表
  6. const DictionarySchema = {
  7. type: { type: String, required: true, maxLength: 200 }, // 类型
  8. name: { type: String, required: true, maxLength: 200 }, // 名称
  9. code: { type: String, required: false, maxLength: 200 }, // 代码
  10. pcode: { type: String, required: false, maxLength: 200 }, // 前一级code
  11. };
  12. const schema = new Schema(DictionarySchema, { toJSON: { virtuals: true } });
  13. schema.index({ id: 1 });
  14. schema.plugin(metaPlugin);
  15. module.exports = app => {
  16. const { mongoose } = app;
  17. return mongoose.model('Dictionary', schema, 'dictionary');
  18. };