2022-09-14 11:32:04 +02:00
|
|
|
const mongoose = require('mongoose').set('debug', false)
|
2019-10-20 01:21:54 +02:00
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
|
|
|
|
|
mongoose.Promise = global.Promise;
|
|
|
|
|
mongoose.level = "F";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
|
|
|
mongoose.plugin(schema => {
|
|
|
|
|
schema.options.usePushEach = true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const OperatorSchema = new Schema({
|
|
|
|
|
idapp: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
username: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2019-11-01 19:59:31 +01:00
|
|
|
name: {
|
2019-10-20 01:21:54 +02:00
|
|
|
type: String,
|
2019-11-01 19:59:31 +01:00
|
|
|
trim: true,
|
2019-10-20 01:21:54 +02:00
|
|
|
},
|
2019-11-01 19:59:31 +01:00
|
|
|
surname: {
|
|
|
|
|
type: String,
|
|
|
|
|
trim: true,
|
|
|
|
|
},
|
|
|
|
|
email: {
|
|
|
|
|
type: String,
|
|
|
|
|
trim: true,
|
|
|
|
|
},
|
2019-11-06 22:29:29 +01:00
|
|
|
usertelegram: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2019-11-01 19:59:31 +01:00
|
|
|
cell: {
|
2019-10-20 01:21:54 +02:00
|
|
|
type: String,
|
2019-11-01 19:59:31 +01:00
|
|
|
trim: true,
|
2019-10-20 01:21:54 +02:00
|
|
|
},
|
|
|
|
|
img: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2019-11-01 19:59:31 +01:00
|
|
|
qualification: { // President, Vice-President, ecc...
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
disciplines: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
certifications: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
webpage: {
|
2019-10-20 01:21:54 +02:00
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
days_working: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
facebook: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-05-27 01:34:06 +02:00
|
|
|
info: { // Biografia HTML
|
2019-11-01 19:59:31 +01:00
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
intro: {
|
2019-10-20 01:21:54 +02:00
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
offers: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2019-11-01 19:59:31 +01:00
|
|
|
skype: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2022-05-27 01:34:06 +02:00
|
|
|
showInTeam: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
},
|
|
|
|
|
arrDisciplines: [{
|
|
|
|
|
type: String,
|
|
|
|
|
}],
|
2019-10-20 01:21:54 +02:00
|
|
|
});
|
|
|
|
|
|
2019-11-06 22:29:29 +01:00
|
|
|
OperatorSchema.statics.getEmailByUsername = async function (idapp, username) {
|
|
|
|
|
const Operator = this;
|
|
|
|
|
|
|
|
|
|
return await Operator.findOne({ idapp, username })
|
|
|
|
|
.then((arrrec) => {
|
|
|
|
|
return ((arrrec) ? arrrec.email : '');
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
console.error('getEmailByUsername', e);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-12 21:34:03 +01:00
|
|
|
OperatorSchema.statics.getFieldsForSearch = function () {
|
2020-03-21 10:28:26 +01:00
|
|
|
return [{ field: 'name', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'surname', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'email', type: tools.FieldType.string },
|
|
|
|
|
{ field: 'cell', type: tools.FieldType.string }]
|
2019-11-12 21:34:03 +01:00
|
|
|
};
|
|
|
|
|
|
2019-11-06 22:29:29 +01:00
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
OperatorSchema.statics.executeQueryTable = function (idapp, params) {
|
2019-11-01 19:59:31 +01:00
|
|
|
params.fieldsearch = this.getFieldsForSearch();
|
2019-10-20 01:21:54 +02:00
|
|
|
return tools.executeQueryTable(this, idapp, params);
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
OperatorSchema.statics.findAllIdApp = function (idapp) {
|
2019-10-20 22:45:09 +02:00
|
|
|
const Operator = this;
|
|
|
|
|
|
|
|
|
|
const myfind = { idapp };
|
|
|
|
|
|
2019-11-01 19:59:31 +01:00
|
|
|
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
|
|
|
|
|
|
|
|
|
|
2019-10-20 22:45:09 +02:00
|
|
|
return Operator.find(myfind, (err, arrrec) => {
|
|
|
|
|
return arrrec
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
const Operator = mongoose.model('Operator', OperatorSchema);
|
|
|
|
|
|
2023-12-09 11:55:58 +01:00
|
|
|
Operator.createIndexes((err) => {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
module.exports = { Operator };
|