66 lines
1.3 KiB
JavaScript
Executable File
66 lines
1.3 KiB
JavaScript
Executable File
|
|
const mongoose = require('mongoose').set('debug', false)
|
|
const Schema = mongoose.Schema;
|
|
|
|
mongoose.Promise = global.Promise;
|
|
mongoose.level = "F";
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
mongoose.plugin(schema => {
|
|
schema.options.usePushEach = true
|
|
});
|
|
|
|
const SubCatProdSchema = new Schema({
|
|
idapp: {
|
|
type: String,
|
|
},
|
|
idCatProd: {
|
|
type: String,
|
|
},
|
|
name: {
|
|
type: String,
|
|
},
|
|
img: {
|
|
type: String,
|
|
},
|
|
icon: {
|
|
type: String,
|
|
},
|
|
color: {
|
|
type: String,
|
|
},
|
|
});
|
|
|
|
SubCatProdSchema.statics.getAllCategories = function (callback) {
|
|
SubCatProd.find(callback)
|
|
}
|
|
|
|
SubCatProdSchema.statics.getSubCatProdById = function (id, callback) {
|
|
SubCatProd.findById(id, callback);
|
|
}
|
|
|
|
SubCatProdSchema.statics.getFieldsForSearch = function () {
|
|
return [{ field: 'name', type: tools.FieldType.string }]
|
|
};
|
|
|
|
SubCatProdSchema.statics.executeQueryTable = function (idapp, params) {
|
|
return tools.executeQueryTable(this, idapp, params);
|
|
};
|
|
|
|
SubCatProdSchema.statics.findAllIdApp = async function (idapp) {
|
|
const myfind = { idapp };
|
|
|
|
return await SubCatProd.find(myfind).sort({ name: 1 });
|
|
};
|
|
|
|
const SubCatProd = mongoose.model('SubCatProd', SubCatProdSchema);
|
|
|
|
SubCatProd.createIndexes((err) => {
|
|
if (err) throw err;
|
|
});
|
|
|
|
|
|
module.exports = SubCatProd;
|