menu.js 952 B

1234567891011121314151617181920212223242526
  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 { ObjectId } = require('mongoose').Types;
  6. // 菜单表
  7. const menu = {
  8. name: { type: String }, // 菜名
  9. params: { type: Array }, // 参数列表
  10. order: { type: Number, default: 0 }, // 已点数量
  11. img: { type: Array }, // 图片
  12. content: { type: String }, // 本品介绍
  13. reserve: { type: Number }, // 卡路里,单位:大卡 reserve
  14. is_use: { type: Boolean, default: true }, // 可以点餐
  15. remark: { type: String },
  16. };
  17. const schema = new Schema(menu, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  18. schema.index({ id: 1 });
  19. schema.index({ name: 1 });
  20. schema.index({ is_use: 1 });
  21. schema.index({ 'meta.createdAt': 1 });
  22. schema.plugin(metaPlugin);
  23. module.exports = app => {
  24. const { mongoose } = app;
  25. return mongoose.model('Menu', schema, 'menu');
  26. };