Table MySkills

This commit is contained in:
Paolo Arena
2021-10-08 00:38:35 +02:00
parent 87739a5847
commit 300ab15ca7
10 changed files with 1421 additions and 903 deletions

102
src/server/models/city.js Executable file
View File

@@ -0,0 +1,102 @@
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 CitySchema = new Schema({
_id: {
type: Number,
},
istat: {
type: String,
},
comune: {
type: String
},
prov: {
type: String,
maxlength: 3,
},
reg: {
type: String,
maxlength: 3,
},
pref: {
type: String,
},
cap: {
type: String,
maxlength: 6,
},
abitanti: {
type: Number,
},
country: {
type: String,
maxlength: 2,
},
});
CitySchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await City.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();
});
CitySchema.statics.findByCity = function (mycity) {
let myregexp = new RegExp(mycity.trim().replace(' ', '|'), 'ig');
const query = [
{ $match: {comune: { $regex: myregexp } } },
{ $sort: { descr: 1 } }
];
return City
.aggregate(query)
.then((arrrec) => {
return arrrec
})
};
CitySchema.statics.getFieldsForSearch = function () {
return [{ field: 'comune', type: tools.FieldType.string },
{ field: 'prov', type: tools.FieldType.string },
{ field: 'reg', type: tools.FieldType.string },
{ field: 'pref', type: tools.FieldType.number },
{ field: 'cap', type: tools.FieldType.number },
]
};
CitySchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
const City = mongoose.model('City', CitySchema);
module.exports = { City };

View File

@@ -23,7 +23,13 @@ const LevelSchema = new Schema({
years_of_exp: {
type: Number,
},
}, {_id: false});
color: {
type: String,
},
theme: {
type: String,
},
});
LevelSchema.pre('save', async function (next) {
if (this.isNew) {
@@ -33,7 +39,6 @@ LevelSchema.pre('save', async function (next) {
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
@@ -47,7 +52,7 @@ LevelSchema.statics.findAllIdApp = function(idapp) {
const Level = this;
const query = [
{$sort: {descr: 1}},
{$sort: {_id: 1}},
];
return Level.aggregate(query).then((arrrec) => {
@@ -58,7 +63,6 @@ LevelSchema.statics.findAllIdApp = function(idapp) {
LevelSchema.statics.getFieldsForSearch = function() {
return [
{field: 'label', type: tools.FieldType.string},
{field: 'descr', type: tools.FieldType.string}];
};

91
src/server/models/myskill.js Executable file
View File

@@ -0,0 +1,91 @@
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,
},
userId: { type: Schema.Types.ObjectId, ref: 'User' },
idSkill: {
type: Number,
},
idStatusSkill: [{
type: Number,
}],
numLevel: {
type: Number,
},
note: {
type: String,
},
date_created: {
type: Date,
default: Date.now,
},
date_updated: {
type: Date,
default: Date.now,
},
});
MySkillSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await MySkill.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;
}
this.date_created = new Date();
}
next();
});
MySkillSchema.statics.findAllIdApp = function(idapp) {
const query = [
{ $match: { idapp } },
{$sort: {descr: 1}},
];
return MySkill.aggregate(query).then((arrrec) => {
return arrrec;
});
};
MySkillSchema.statics.getFieldsForSearch = function() {
return [{ field: 'idSkill', type: tools.FieldType.Number }]
};
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};

View File

@@ -14,15 +14,46 @@ mongoose.plugin(schema => {
});
const SectorSchema = new Schema({
_id: {
type: Number,
},
descr: {
type: String,
},
idSector: {
type: Number
},
icon: {
type: String,
},
img: {
type: String,
},
color: {
type: String,
},
theme: {
type: String,
},
main: {
type: Boolean,
}
});
SectorSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await Sector.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();
});
SectorSchema.statics.findAllIdApp = function (idapp) {

View File

@@ -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 }]

View File

@@ -0,0 +1,75 @@
const mongoose = require('mongoose').set('debug', false)
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,
},
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 = function (idapp) {
const StatusSkill = this;
const query = [
{ $sort: { descr: 1 } }
];
return StatusSkill
.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);
module.exports = { StatusSkill };

File diff suppressed because it is too large Load Diff