12345678910111213141516171819202122232425262728293031 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const moment = require('moment');
- const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
- const { ObjectId } = require('mongoose').Types;
- const meal = new Schema({
- list: { type: Array }, // 点餐内容
- reserve: { type: Number, default: 0 }, // 卡路里,热量
- is_use: { type: String, default: '0' }, // 是否使用:0-待使用;1-待评价;2-已完成;3-失效
- });
- // 订餐表
- const order = {
- user_id: { type: String }, // 用户id(预留)
- date: { type: String, required: true }, // 日期
- breakfast: { type: meal }, // 早餐
- lunch: { type: meal }, // 午餐
- dinner: { type: meal }, // 晚餐
- openid: { type: String }, // openid
- remark: { type: String },
- };
- const schema = new Schema(order, { 'multi-tenancy': true, toJSON: { virtuals: true } });
- schema.index({ id: 1 });
- schema.index({ date: 1 });
- schema.index({ user_id: 1 });
- schema.index({ openid: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('Order', schema, 'order');
- };
|