Files
freeplanet_serverside/src/server/models/category.js
2023-12-09 11:55:58 +01:00

59 lines
1.2 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 CategorySchema = new Schema({
idapp: {
type: String,
},
name: {
type: String,
unique: true,
index: true,
},
img: {
type: String,
},
});
CategorySchema.statics.getAllCategories = function (callback) {
Category.find(callback)
}
CategorySchema.statics.getCategoryById = function (id, callback) {
Category.findById(id, callback);
}
CategorySchema.statics.getFieldsForSearch = function () {
return [{ field: 'name', type: tools.FieldType.string }]
};
CategorySchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params);
};
CategorySchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return await Category.find(myfind);
};
const Category = mongoose.model('Category', CategorySchema);
Category.createIndexes((err) => {
if (err) throw err;
});
module.exports = { Category };