Files
freeplanet_serverside/src/server/models/category.js

59 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-11-28 14:20:22 +01:00
2022-09-14 11:32:04 +02:00
const mongoose = require('mongoose').set('debug', false)
2020-12-21 02:16:42 +01:00
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
2023-11-28 14:20:22 +01:00
const tools = require('../tools/general');
2020-12-21 02:16:42 +01:00
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const CategorySchema = new Schema({
2023-11-28 14:20:22 +01:00
idapp: {
type: String,
},
2020-12-21 02:16:42 +01:00
name: {
type: String,
unique: true,
index: true,
2023-11-28 14:20:22 +01:00
},
img: {
type: String,
},
2020-12-21 02:16:42 +01:00
});
2023-11-28 14:20:22 +01:00
CategorySchema.statics.getAllCategories = function (callback) {
2020-12-21 02:16:42 +01:00
Category.find(callback)
}
2023-11-28 14:20:22 +01:00
CategorySchema.statics.getCategoryById = function (id, callback) {
2020-12-21 02:16:42 +01:00
Category.findById(id, callback);
}
2023-11-28 14:20:22 +01:00
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);
2023-12-09 11:55:58 +01:00
Category.createIndexes((err) => {
if (err) throw err;
});
2023-11-28 14:20:22 +01:00
module.exports = { Category };