2021-10-08 00:38:35 +02:00
|
|
|
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 MySkillSchema = new Schema({
|
|
|
|
|
_id: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
|
|
|
|
idapp: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
2021-10-28 00:38:10 +02:00
|
|
|
userId: {type: Schema.Types.ObjectId, ref: 'User'},
|
2021-10-08 00:38:35 +02:00
|
|
|
idSkill: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
2021-10-28 00:38:10 +02:00
|
|
|
idStatusSkill: [
|
|
|
|
|
{
|
|
|
|
|
type: Number,
|
|
|
|
|
}],
|
|
|
|
|
idCity: [
|
|
|
|
|
{
|
|
|
|
|
type: Number,
|
|
|
|
|
}],
|
2021-10-08 00:38:35 +02:00
|
|
|
numLevel: {
|
|
|
|
|
type: Number,
|
|
|
|
|
},
|
2021-10-28 00:38:10 +02:00
|
|
|
photos: [
|
|
|
|
|
{
|
|
|
|
|
imagefile: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
alt: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
description: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
}],
|
2021-10-08 00:38:35 +02:00
|
|
|
note: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2021-10-28 00:38:10 +02:00
|
|
|
subTitle: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2021-10-08 00:38:35 +02:00
|
|
|
date_created: {
|
|
|
|
|
type: Date,
|
|
|
|
|
default: Date.now,
|
|
|
|
|
},
|
|
|
|
|
date_updated: {
|
|
|
|
|
type: Date,
|
|
|
|
|
default: Date.now,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-10-28 00:38:10 +02:00
|
|
|
MySkillSchema.pre('save', async function(next) {
|
2021-10-08 00:38:35 +02:00
|
|
|
if (this.isNew) {
|
2021-10-28 00:38:10 +02:00
|
|
|
const myrec = await MySkill.findOne().limit(1).sort({_id: -1});
|
2021-10-08 00:38:35 +02:00
|
|
|
if (!!myrec) {
|
|
|
|
|
if (myrec._doc._id === 0)
|
|
|
|
|
this._id = 1;
|
|
|
|
|
else
|
|
|
|
|
this._id = myrec._doc._id + 1;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
this._id = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.date_created = new Date();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
MySkillSchema.statics.findAllIdApp = function(idapp) {
|
|
|
|
|
|
|
|
|
|
const query = [
|
2021-10-28 00:38:10 +02:00
|
|
|
{$match: {idapp}},
|
2021-10-08 00:38:35 +02:00
|
|
|
{$sort: {descr: 1}},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return MySkill.aggregate(query).then((arrrec) => {
|
|
|
|
|
return arrrec;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MySkillSchema.statics.getFieldsForSearch = function() {
|
2021-10-28 00:38:10 +02:00
|
|
|
return [{field: 'idSkill', type: tools.FieldType.Number}];
|
2021-10-08 00:38:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MySkillSchema.statics.executeQueryTable = function(idapp, params) {
|
|
|
|
|
params.fieldsearch = this.getFieldsForSearch();
|
|
|
|
|
return tools.executeQueryTable(this, idapp, params);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const MySkill = mongoose.model('MySkill', MySkillSchema);
|
|
|
|
|
|
|
|
|
|
module.exports = {MySkill};
|