Table MySkills
This commit is contained in:
@@ -14,12 +14,15 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const SkillSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
idSector: {
|
||||
type: String
|
||||
},
|
||||
idSector: [{
|
||||
type: Number
|
||||
}],
|
||||
icon: {
|
||||
type: String,
|
||||
},
|
||||
@@ -43,6 +46,25 @@ SkillSchema.statics.findAllIdApp = function (idapp) {
|
||||
|
||||
};
|
||||
|
||||
SkillSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await Skill.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();
|
||||
});
|
||||
|
||||
|
||||
|
||||
SkillSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'label', type: tools.FieldType.string },
|
||||
{ field: 'descr', type: tools.FieldType.string }]
|
||||
|
||||
Reference in New Issue
Block a user