cart.js 590 B

123456789101112131415161718192021
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. // 购物车表
  5. const cart = {
  6. list: { type: Array, zh: '购买商品' }, //
  7. total: { type: Number, zh: '总价' }, //
  8. table: { type: String, zh: '桌号' }, //
  9. };
  10. const schema = new Schema(cart, {
  11. toJSON: { getters: true, virtuals: true },
  12. });
  13. schema.index({ id: 1 });
  14. schema.index({ 'meta.createdAt': 1 });
  15. schema.plugin(metaPlugin);
  16. module.exports = app => {
  17. const { mongoose } = app;
  18. return mongoose.model('Cart', schema, 'cart');
  19. };