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

84 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-09-14 11:32:04 +02:00
const mongoose = require('mongoose').set('debug', false)
2021-10-08 00:38:35 +02:00
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 StatusSkillSchema = new Schema({
_id: {
type: Number,
},
descr: {
type: String,
},
color: {
type: String,
},
icon: {
type: String,
},
2021-10-08 00:38:35 +02:00
theme: {
type: String,
},
});
StatusSkillSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await StatusSkill.findOne().limit(1).sort({_id:-1});
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
}
next();
});
StatusSkillSchema.statics.findAllIdApp = async function (idapp) {
2021-10-08 00:38:35 +02:00
const StatusSkill = this;
const query = [
{ $sort: { descr: 1 } }
];
return await StatusSkill
2021-10-08 00:38:35 +02:00
.aggregate(query)
.then((arrrec) => {
return arrrec
})
};
StatusSkillSchema.statics.getFieldsForSearch = function () {
return [{ field: 'descr', type: tools.FieldType.string }]
};
StatusSkillSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
const StatusSkill = mongoose.model('StatusSkill', StatusSkillSchema);
StatusSkill.createIndexes()
.then(() => { })
.catch((err) => { throw err; });
2023-12-09 11:55:58 +01:00
2021-10-08 00:38:35 +02:00
module.exports = { StatusSkill };