- select specializz.
This commit is contained in:
@@ -26,6 +26,11 @@ const MySkillSchema = new Schema({
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
idSubSkill: [
|
||||
{
|
||||
type: Number,
|
||||
default: 0,
|
||||
}],
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
|
||||
81
src/server/models/subskill.js
Executable file
81
src/server/models/subskill.js
Executable file
@@ -0,0 +1,81 @@
|
||||
const mongoose = require('mongoose').set('debug', false)
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const SubSkillSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
idSkill: {
|
||||
type: Number,
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
SubSkillSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const SubSkill = this;
|
||||
|
||||
const query = [
|
||||
{ $sort: { descr: 1 } }
|
||||
];
|
||||
|
||||
return SubSkill
|
||||
.aggregate(query)
|
||||
.then((arrrec) => {
|
||||
return arrrec
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
SubSkillSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await SubSkill.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();
|
||||
});
|
||||
|
||||
|
||||
|
||||
SubSkillSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'label', type: tools.FieldType.string },
|
||||
{ field: 'descr', type: tools.FieldType.string }]
|
||||
};
|
||||
|
||||
SubSkillSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
|
||||
const SubSkill = mongoose.model('SubSkill', SubSkillSchema);
|
||||
|
||||
module.exports = { SubSkill };
|
||||
Reference in New Issue
Block a user