Lista Doni Navi 3

This commit is contained in:
Paolo Arena
2020-03-25 18:26:51 +01:00
parent b9d899ba72
commit d59ee578c9
6 changed files with 485 additions and 209 deletions

View File

@@ -0,0 +1,178 @@
const mongoose = require('mongoose');
const _ = require('lodash');
const tools = require('../tools/general');
const { ListaIngresso } = require('./listaingresso');
const { Settings } = require('./settings');
const { User } = require('./user');
const { ObjectID } = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
const NavePersistenteSchema = new mongoose.Schema({
idapp: {
type: String,
required: true,
},
index: {
type: Number
},
riga: {
type: Number,
},
col: {
type: Number,
},
riga1don: {
type: Number,
},
col1don: {
type: Number,
},
date_start: {
type: Date
},
date_gift_chat_open: {
type: Date
},
link_chat: {
type: String,
},
provvisoria: {
type: Boolean,
},
DoniAttesaDiConferma: {
type: Number,
},
DoniMancanti: {
type: Number,
},
DoniConfermati: {
type: Number,
},
note_bot: {
type: String
},
note_interne: {
type: String
},
tutor: {
type: String
},
tutor_namesurname: {
type: String
}
});
NavePersistenteSchema.statics.findById = function (idapp, id) {
const NavePersistente = this;
const myquery = getQueryProj({ idapp, '_id': ObjectID(id) });
return NavePersistente.aggregate(myquery);
};
NavePersistenteSchema.statics.getFieldsForSearch = function () {
return [{ field: 'ind_order', type: tools.FieldType.number },
{ field: 'col', type: tools.FieldType.number }]
};
NavePersistenteSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
NavePersistenteSchema.statics.findAllIdApp = function (idapp) {
const NavePersistente = this;
const myfind = { idapp };
return NavePersistente.find(myfind).sort({ riga: 1, col: 1 });
};
NavePersistenteSchema.statics.findByRigaColByDonatore = function (idapp, riga, col, offset) {
const NavePersistente = this;
mypos = {
riga,
col,
numup: 3 + offset,
};
tools.getRigaColByPosUp(mypos);
return NavePersistente.findOne({ idapp, riga: mypos.riga, col: mypos.col });
};
NavePersistenteSchema.statics.findByRigaCol = function (idapp, riga, col) {
const NavePersistente = this;
return NavePersistente.findOne({ idapp, riga, col });
};
NavePersistenteSchema.statics.getLastRigaCol = async function (idapp) {
return NavePersistente.findOne({ idapp }).sort({ _id: -1 });
};
NavePersistenteSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await NavePersistente.findOne().limit(1).sort({_id:-1});
if (!!myrec) {
this.index = myrec._doc.index + 1;
} else {
this.index = 1;
}
}
next();
});
NavePersistenteSchema.statics.addRecordNavePersistenteByParams = async function (params) {
// Check if Exist:
const giapresente = await NavePersistente.findOne({
idapp: params.idapp,
riga: params.riga,
col: params.col
});
if (!giapresente) {
let myNavePersistente = new NavePersistente({
idapp: params.idapp,
riga: params.riga,
col: params.col,
riga1don: params.riga1don,
col1don: params.col1don,
date_start: params.date_start,
date_gift_chat_open: params.date_gift_chat_open,
provvisoria: params.provvisoria,
});
return await myNavePersistente.save();
}
return false;
};
const NavePersistente = mongoose.model('NavePersistente', NavePersistenteSchema);
module.exports = { NavePersistente };