From 049e88221086e98ab88963e6531846bc120e7ee0 Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Tue, 12 Nov 2019 21:34:03 +0100 Subject: [PATCH] - Table of Disciplines #101 - Insert Facebook bar to the Site #97 --- server/models/contribtype.js | 5 ++ server/models/discipline.js | 88 +++++++++++++++++++++++++++++++++++ server/models/operator.js | 4 ++ server/models/permission.js | 1 + server/models/settings.js | 5 ++ server/models/where.js | 5 ++ server/router/index_router.js | 7 ++- server/tools/general.js | 1 + 8 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 server/models/discipline.js diff --git a/server/models/contribtype.js b/server/models/contribtype.js index 4d71c14..d8cd146 100644 --- a/server/models/contribtype.js +++ b/server/models/contribtype.js @@ -24,7 +24,12 @@ const ContribtypeSchema = new Schema({ } }); +ContribtypeSchema.statics.getFieldsForSearch = function () { + return ['label'] +}; + ContribtypeSchema.statics.executeQueryTable = function (idapp, params) { + params.fieldsearch = this.getFieldsForSearch(); return tools.executeQueryTable(this, idapp, params); }; diff --git a/server/models/discipline.js b/server/models/discipline.js new file mode 100644 index 0000000..385f8e9 --- /dev/null +++ b/server/models/discipline.js @@ -0,0 +1,88 @@ +const mongoose = require('mongoose'); +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 DisciplineSchema = new Schema({ + idapp: { + type: String, + }, + order: { + type: Number, + }, + typol_code: { + type: String, + }, + label: { + type: String, + }, + description: { + type: String, + }, + linkpage: { + type: String, + }, + color: { + type: String, + }, + icon: { + type: String, + }, + img_small: { + type: String, + }, + img: { + type: String, + }, + showinnewsletter: { + type: Boolean, + }, + showinhome: { + type: Boolean, + }, + teachers: [{ + username: { + type: String, + } + }], +}); + +DisciplineSchema.statics.findAllIdApp = function (idapp) { + const Discipline = this; + + const query = [ + { $match: { idapp } }, + { $sort: { order: 1 } } + ]; + + return Discipline + .aggregate(query) + .then((arrrec) => { + return arrrec + }) + +}; + + +DisciplineSchema.statics.getFieldsForSearch = function () { + return ['label', 'description'] +}; + +DisciplineSchema.statics.executeQueryTable = function (idapp, params) { + params.fieldsearch = this.getFieldsForSearch(); + return tools.executeQueryTable(this, idapp, params); +}; + +const Discipline = mongoose.model('Discipline', DisciplineSchema); + +module.exports = { Discipline }; diff --git a/server/models/operator.js b/server/models/operator.js index 271c158..3dcd4c1 100644 --- a/server/models/operator.js +++ b/server/models/operator.js @@ -88,6 +88,10 @@ OperatorSchema.statics.getEmailByUsername = async function (idapp, username) { }); }; +OperatorSchema.statics.getFieldsForSearch = function () { + return ['name', 'surname', 'email', 'cell'] +}; + OperatorSchema.statics.executeQueryTable = function (idapp, params) { params.fieldsearch = this.getFieldsForSearch(); diff --git a/server/models/permission.js b/server/models/permission.js index 03d6c25..b558c7c 100644 --- a/server/models/permission.js +++ b/server/models/permission.js @@ -41,6 +41,7 @@ PermissionSchema.pre('save', async function (next) { }); PermissionSchema.statics.executeQueryTable = function (idapp, params) { + params.fieldsearch = this.getFieldsForSearch(); return tools.executeQueryTable(this, 0, params); }; diff --git a/server/models/settings.js b/server/models/settings.js index 42f599c..6991d6a 100644 --- a/server/models/settings.js +++ b/server/models/settings.js @@ -33,7 +33,12 @@ const SettingsSchema = new Schema({ } }); +SettingsSchema.statics.getFieldsForSearch = function () { + return ['key', 'value_str'] +}; + SettingsSchema.statics.executeQueryTable = function (idapp, params) { + params.fieldsearch = this.getFieldsForSearch(); return tools.executeQueryTable(this, idapp, params); }; diff --git a/server/models/where.js b/server/models/where.js index 3e0b93d..ccf5b1a 100644 --- a/server/models/where.js +++ b/server/models/where.js @@ -30,7 +30,12 @@ const WhereSchema = new Schema({ }, }); +WhereSchema.statics.getFieldsForSearch = function () { + return ['placename'] +}; + WhereSchema.statics.executeQueryTable = function (idapp, params) { + params.fieldsearch = this.getFieldsForSearch(); return tools.executeQueryTable(this, idapp, params); }; diff --git a/server/router/index_router.js b/server/router/index_router.js index e4b9c1f..c8e7f61 100644 --- a/server/router/index_router.js +++ b/server/router/index_router.js @@ -16,6 +16,7 @@ const { Operator } = require('../models/operator'); const { Where } = require('../models/where'); const { MyEvent } = require('../models/myevent'); const { Contribtype } = require('../models/contribtype'); +const { Discipline } = require('../models/discipline'); const { Settings } = require('../models/settings'); const { SendMsg } = require('../models/sendmsg'); const { Permission } = require('../models/permission'); @@ -143,6 +144,8 @@ function getTableByTableName(tablename) { mytable = MyEvent; else if (tablename === 'contribtype') mytable = Contribtype; + else if (tablename === 'disciplines') + mytable = Discipline; else if (tablename === 'settings') mytable = Settings; else if (tablename === 'permissions') @@ -339,11 +342,12 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) => const operators = Operator.findAllIdApp(idapp); const wheres = Where.findAllIdApp(idapp); const contribtype = Contribtype.findAllIdApp(idapp); + const disciplines = Discipline.findAllIdApp(idapp); const settings = Settings.findAllIdApp(idapp); const permissions = Permission.findAllIdApp(); - return Promise.all([bookedevent, eventlist, operators, wheres, contribtype, settings, permissions]) + return Promise.all([bookedevent, eventlist, operators, wheres, contribtype, settings, permissions, disciplines]) .then((arrdata) => { // console.table(arrdata); res.send({ @@ -354,6 +358,7 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) => contribtype: arrdata[4], settings: arrdata[5], permissions: arrdata[6], + disciplines: arrdata[7], }); }) .catch((e) => { diff --git a/server/tools/general.js b/server/tools/general.js index 35c76c3..de5ba2c 100644 --- a/server/tools/general.js +++ b/server/tools/general.js @@ -42,6 +42,7 @@ module.exports = { select: 32, number: 64, typeinrec: 128, + multiselect: 256, }, MAX_PHASES: 5,