Iscrizione Conacreis e Arcadei
This commit is contained in:
198
src/server/models/iscrittiArcadei.js
Executable file
198
src/server/models/iscrittiArcadei.js
Executable file
@@ -0,0 +1,198 @@
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
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 IscrittiArcadeiSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
numTesseraInterna: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
surname: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
email2: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
residency_address: {
|
||||
type: String,
|
||||
},
|
||||
residency_city: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
residency_province: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
residency_country: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
residency_zipcode: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
dateofbirth: {
|
||||
type: Date,
|
||||
},
|
||||
born_city: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
born_province: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
born_country: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
cell_phone: {
|
||||
type: String,
|
||||
},
|
||||
cell_phone2: {
|
||||
type: String,
|
||||
},
|
||||
newsletter_on: {
|
||||
type: Boolean,
|
||||
},
|
||||
terms: {
|
||||
type: Boolean,
|
||||
},
|
||||
metodo_pagamento: {
|
||||
type: Number,
|
||||
},
|
||||
doctype: {
|
||||
type: String,
|
||||
},
|
||||
documentnumber: {
|
||||
type: String,
|
||||
},
|
||||
ha_pagato: {
|
||||
type: Boolean,
|
||||
},
|
||||
iscrizione_compilata: {
|
||||
type: Boolean,
|
||||
},
|
||||
dateofreg: {
|
||||
type: Date,
|
||||
},
|
||||
dateofapproved: {
|
||||
type: Date,
|
||||
},
|
||||
codiceArcadei: {
|
||||
type: String,
|
||||
},
|
||||
annoTesseramento: {
|
||||
type: Number,
|
||||
},
|
||||
motivazioni: {
|
||||
type: String,
|
||||
},
|
||||
categorie_interesse: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
altre_comunicazioni: {
|
||||
type: String,
|
||||
},
|
||||
come_ci_hai_conosciuto: {
|
||||
type: String,
|
||||
},
|
||||
note: {
|
||||
type: String,
|
||||
},
|
||||
quota_versata: {
|
||||
type: Number,
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
IscrittiArcadeiSchema.pre('save', async function(next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await IscrittiArcadei.findOne().limit(1).sort({numTesseraInterna: -1});
|
||||
if (!!myrec) {
|
||||
this.numTesseraInterna = myrec._doc.numTesseraInterna + 1;
|
||||
} else {
|
||||
this.numTesseraInterna = 0;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
var IscrittiArcadei = module.exports = mongoose.model('IscrittiArcadei', IscrittiArcadeiSchema);
|
||||
|
||||
module.exports.getFieldsForSearch = function() {
|
||||
return [
|
||||
{field: 'name', type: tools.FieldType.string},
|
||||
{field: 'surname', type: tools.FieldType.string},
|
||||
{field: 'email', type: tools.FieldType.string}];
|
||||
};
|
||||
|
||||
module.exports.executeQueryTable = function(idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
module.exports.getLastRec = async function(idapp) {
|
||||
const lastrec = await IscrittiArcadei.find({idapp}).sort({dateofreg: -1}).limit(1);
|
||||
if (!!lastrec) {
|
||||
return lastrec[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.getNameSurnameByEmail = async function(idapp, email) {
|
||||
return await IscrittiArcadei.findOne({
|
||||
idapp, email,
|
||||
}, {name: 1, surname: 1}).then((rec) => {
|
||||
return (!!rec) ? `${rec.name} ${rec.surname}` : '';
|
||||
}).catch((e) => {
|
||||
console.error('getNameSurnameByUsername', e);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.findByEmail = function(idapp, email) {
|
||||
|
||||
return IscrittiArcadei.findOne({
|
||||
'idapp': idapp,
|
||||
'email': email,
|
||||
$or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}],
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.findAllIdApp = async function(idapp) {
|
||||
|
||||
const myfind = {idapp};
|
||||
|
||||
return await IscrittiArcadei.find(myfind, (err, arrrec) => {
|
||||
return arrrec;
|
||||
});
|
||||
};
|
||||
@@ -17,7 +17,7 @@ const MyElemSchema = new Schema({
|
||||
type: String,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
type: Number,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
@@ -25,6 +25,24 @@ const MyElemSchema = new Schema({
|
||||
container: {
|
||||
type: String,
|
||||
},
|
||||
container2: {
|
||||
type: String,
|
||||
},
|
||||
container3: {
|
||||
type: String,
|
||||
},
|
||||
number: {
|
||||
type: String,
|
||||
},
|
||||
imgback: {
|
||||
type: String,
|
||||
},
|
||||
ratio: {
|
||||
type: String,
|
||||
},
|
||||
containerHtml: {
|
||||
type: String,
|
||||
},
|
||||
size: {
|
||||
type: String,
|
||||
},
|
||||
@@ -35,6 +53,18 @@ const MyElemSchema = new Schema({
|
||||
height: {
|
||||
type: Number,
|
||||
},
|
||||
heightimg: {
|
||||
type: Number,
|
||||
},
|
||||
widthimg: {
|
||||
type: Number,
|
||||
},
|
||||
width: {
|
||||
type: Number,
|
||||
},
|
||||
link: {
|
||||
type: String,
|
||||
},
|
||||
onlyif_logged: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -47,6 +77,25 @@ const MyElemSchema = new Schema({
|
||||
class: {
|
||||
type: String,
|
||||
},
|
||||
styleadd: {
|
||||
type: String,
|
||||
},
|
||||
list: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String
|
||||
},
|
||||
order: {
|
||||
type: Number
|
||||
},
|
||||
alt: {
|
||||
type: String
|
||||
},
|
||||
description: {
|
||||
type: String
|
||||
}
|
||||
}
|
||||
],
|
||||
});
|
||||
|
||||
MyElemSchema.statics.getFieldsForSearch = function () {
|
||||
@@ -64,9 +113,7 @@ MyElemSchema.statics.findAllIdApp = async function (idapp) {
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
return await MyElem.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
return await MyElem.find(myfind).sort({ order: 1 });
|
||||
};
|
||||
|
||||
const MyElem = mongoose.model('MyElem', MyElemSchema);
|
||||
|
||||
Reference in New Issue
Block a user