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

View File

@@ -41,6 +41,9 @@ const { Contribtype } = require('../models/contribtype');
const { PaymentType } = require('../models/paymenttype');
const { Discipline } = require('../models/discipline');
const { Skill } = require('../models/skill');
const { MySkill } = require('../models/myskill');
const { StatusSkill } = require('../models/statusSkill');
const { City } = require('../models/city');
const { Sector } = require('../models/sector');
const { Level } = require('../models/level');
const { Newstosent } = require('../models/newstosent');
@@ -286,6 +289,12 @@ function getTableByTableName(tablename) {
mytable = Graduatoria;
else if (tablename === 'skills')
mytable = Skill;
else if (tablename === 'myskills')
mytable = MySkill;
else if (tablename === 'statusSkills')
mytable = StatusSkill;
else if (tablename === 'citys')
mytable = City;
else if (tablename === 'sectors')
mytable = Sector;
else if (tablename === 'levels')
@@ -314,12 +323,65 @@ router.post('/settable', authenticate, (req, res) => {
}
}
if (shared_consts.TABLES_USER_ID.includes(params.table)) {
mydata.userId = req.user._id;
}
let mytablerec = new mytable(mydata);
// console.log('mytablerec', mytablerec);
const mytablestrutt = getTableByTableName(params.table);
return mytablerec.save()
.then(rec => {
// tools.mylog('rec', rec);
return res.send(rec);
}).catch((e) => {
if (e.code === 11000) {
const id = mytablerec._id;
delete mytablerec._doc['_id'];
const myfields = mytablerec._doc;
if (!myfields.userId) {
myfields.userId = req.user._id.toString();
}
return mytablestrutt.findByIdAndUpdate(id, { $set: myfields }).then(async (rec) => {
return res.send(rec);
}).catch((err) => {
tools.mylog('error: ', err.message);
return res.status(400).send(err);
})
} else {
console.log(e.message);
}
});
});
router.post('/setsubrec', authenticate, (req, res) => {
const params = req.body;
const mytable = getTableByTableName(params.table);
const mydata = req.body.data;
mydata.idapp = req.user.idapp;
let mytablerec = new mytable(mydata);
// console.log('mytablerec', mytablerec);
const mytablestrutt = getTableByTableName(params.table);
const rec = mytablestrutt.createNewSubRecord(mydata.idapp, req)
.then(rec => {
// tools.mylog('rec', rec);
return res.send(rec);
}).catch((e) => {
});
return res.send(rec);
return mytablerec.save()
.then(rec => {
// tools.mylog('rec', rec);
@@ -477,6 +539,10 @@ router.patch('/chval', authenticate, async (req, res) => {
}
}
if (shared_consts.TABLES_UPDATE_LASTMODIFIED.includes(mydata.table)) {
fieldsvalue.date_updated = new Date();
}
await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }).then(async (rec) => {
// tools.mylogshow(' REC TO MODIFY: ', rec);
if (!rec) {
@@ -1213,6 +1279,7 @@ function load(req, res, version) {
let departments = Department.findAllIdApp(idapp);
let levels = Level.findAllIdApp(idapp);
let skills = Skill.findAllIdApp(idapp);
let statusSkills = StatusSkill.findAllIdApp(idapp);
let sectors = Sector.findAllIdApp(idapp);
let cart = null;
let orderscart = null;
@@ -1234,7 +1301,7 @@ function load(req, res, version) {
return Promise.all([bookedevent, eventlist, operators, wheres, contribtype, settings, permissions, disciplines, newstosent, mailinglist, mypage, gallery, paymenttype, calcstat, calzoom, producers, cart, storehouses, departments, orderscart, groups, resps, workers, internalpages,
levels, skills, sectors ])
levels, skills, sectors, statusSkills ])
.then((arrdata) => {
// console.table(arrdata);
const myuser = req.user;
@@ -1271,6 +1338,7 @@ function load(req, res, version) {
levels: arrdata[24],
skills: arrdata[25],
sectors: arrdata[26],
statusSkills: arrdata[27],
});
})
.catch((e) => {

View File

@@ -63,6 +63,7 @@ mongoose.set('debug', process.env.DEBUG);
const cfgserver = mongoose.model('cfgserver');
const { ObjectID } = require('mongodb');
myLoad().then(ris => {
const { User } = require('./models/user');
@@ -228,6 +229,8 @@ async function mystart() {
testmsgwebpush();
faitest();
// tools.sendNotifToAdmin('Riparti', 'Riparti');
// sendemail.testemail('2', 'it');
@@ -406,4 +409,21 @@ async function inizia() {
// console.log(link2);
// }
async function faitest() {
console.log('Fai Test:')
const testfind = false;
if (testfind) {
const {City} = require('./models/city');
let miacity = 'roma';
const ris = await City.findByCity(miacity);
console.log('ris', ris);
}
}
module.exports = { app };

View File

@@ -39,7 +39,9 @@ module.exports = {
'In Contanti alla CNM'
],
TABLES_ID_NUMBER: ['permissions', 'levels'],
TABLES_ID_NUMBER: ['permissions', 'levels', 'statusSkills', 'sectors', 'skills', 'city', 'myskills'],
TABLES_USER_ID: ['myskills'],
TABLES_UPDATE_LASTMODIFIED: ['myskills'],
CashType: {
None: 0,