12345678910111213141516171819202122232425262728293031 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
- // 商品表
- const goods = {
- name: { type: String, required: false, zh: '商品名称' }, //
- type: { type: String, required: false, zh: '商品类型' }, //
- spec: { type: String, required: false, zh: '商品规格' }, //
- stock: { type: Number, required: false, zh: '商品库存' }, //
- price: { type: Number, required: false, zh: '商品价格' }, //
- file: { type: Array, zh: '商品图片' }, //
- is_use: { type: String, required: false, zh: '是否启用', default: '0' }, //
- };
- const schema = new Schema(goods, {
- toJSON: { getters: true, virtuals: true },
- });
- schema.index({ id: 1 });
- schema.index({ 'meta.createdAt': 1 });
- schema.index({ name: 1 });
- schema.index({ type: 1 });
- schema.index({ spec: 1 });
- schema.index({ stock: 1 });
- schema.index({ price: 1 });
- schema.index({ is_use: 1 });
- schema.plugin(metaPlugin);
- module.exports = app => {
- const { mongoose } = app;
- return mongoose.model('Goods', schema, 'goods');
- };
|