Sorting fixed
- added tables Skills, Sectors,
This commit is contained in:
72
src/server/models/level.js
Executable file
72
src/server/models/level.js
Executable file
@@ -0,0 +1,72 @@
|
||||
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 LevelSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
years_of_exp: {
|
||||
type: Number,
|
||||
},
|
||||
}, {_id: false});
|
||||
|
||||
LevelSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await Level.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();
|
||||
});
|
||||
|
||||
|
||||
LevelSchema.statics.findAllIdApp = function(idapp) {
|
||||
const Level = this;
|
||||
|
||||
const query = [
|
||||
{$sort: {descr: 1}},
|
||||
];
|
||||
|
||||
return Level.aggregate(query).then((arrrec) => {
|
||||
return arrrec;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
LevelSchema.statics.getFieldsForSearch = function() {
|
||||
return [
|
||||
{field: 'label', type: tools.FieldType.string},
|
||||
{field: 'descr', type: tools.FieldType.string}];
|
||||
};
|
||||
|
||||
LevelSchema.statics.executeQueryTable = function(idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
const Level = mongoose.model('Level', LevelSchema);
|
||||
|
||||
module.exports = {Level};
|
||||
55
src/server/models/sector.js
Executable file
55
src/server/models/sector.js
Executable file
@@ -0,0 +1,55 @@
|
||||
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 SectorSchema = new Schema({
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
SectorSchema.statics.findAllIdApp = function (idapp) {
|
||||
const Sector = this;
|
||||
|
||||
const query = [
|
||||
{ $sort: { descr: 1 } }
|
||||
];
|
||||
|
||||
return Sector
|
||||
.aggregate(query)
|
||||
.then((arrrec) => {
|
||||
return arrrec
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
SectorSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'descr', type: tools.FieldType.string }]
|
||||
};
|
||||
|
||||
SectorSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
|
||||
const Sector = mongoose.model('Sector', SectorSchema);
|
||||
|
||||
module.exports = { Sector };
|
||||
59
src/server/models/skill.js
Executable file
59
src/server/models/skill.js
Executable file
@@ -0,0 +1,59 @@
|
||||
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 SkillSchema = new Schema({
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
idSector: {
|
||||
type: String
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
SkillSchema.statics.findAllIdApp = function (idapp) {
|
||||
const Skill = this;
|
||||
|
||||
const query = [
|
||||
{ $sort: { descr: 1 } }
|
||||
];
|
||||
|
||||
return Skill
|
||||
.aggregate(query)
|
||||
.then((arrrec) => {
|
||||
return arrrec
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
SkillSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'label', type: tools.FieldType.string },
|
||||
{ field: 'descr', type: tools.FieldType.string }]
|
||||
};
|
||||
|
||||
SkillSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
|
||||
const Skill = mongoose.model('Skill', SkillSchema);
|
||||
|
||||
module.exports = { Skill };
|
||||
Reference in New Issue
Block a user