- Iscrizione Conacreis
This commit is contained in:
@@ -19,6 +19,10 @@ const IscrittiConacreisSchema = new Schema({
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
numTesseraInterna: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
trim: true,
|
||||
@@ -81,6 +85,9 @@ const IscrittiConacreisSchema = new Schema({
|
||||
metodo_pagamento: {
|
||||
type: Number,
|
||||
},
|
||||
ha_pagato: {
|
||||
type: Boolean,
|
||||
},
|
||||
iscrizione_compilata: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -120,6 +127,20 @@ const IscrittiConacreisSchema = new Schema({
|
||||
|
||||
});
|
||||
|
||||
IscrittiConacreisSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await IscrittiConacreis.findOne().limit(1).sort({ numTesseraInterna: -1 });
|
||||
if (!!myrec) {
|
||||
this.numTesseraInterna = myrec._doc.numTesseraInterna + 1;
|
||||
} else {
|
||||
this.numTesseraInterna = 0;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
var IscrittiConacreis = module.exports = mongoose.model('IscrittiConacreis', IscrittiConacreisSchema);
|
||||
|
||||
module.exports.getFieldsForSearch = function () {
|
||||
@@ -128,6 +149,8 @@ module.exports.getFieldsForSearch = function () {
|
||||
{ field: 'email', type: tools.FieldType.string }]
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
|
||||
Reference in New Issue
Block a user