- catalogo

- corretto logica del RefreshToken che non richiedeva il nuovo token, quindi scadeva tutte le volte, richiedendo sempre l'accesso !
This commit is contained in:
Surya Paolo
2025-01-07 16:50:55 +01:00
parent 7f6ed73763
commit 9fb7df56e6
24 changed files with 1199 additions and 59 deletions

View File

@@ -235,11 +235,11 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
myaccount.totTransato = 0;
}
myaccount.totTransato += Math.abs(amount);
if (!myaccount.numtransactions)
myaccount.numtransactions = 0;
myaccount.numtransactions++;
myaccount.date_updated = new Date();
myaccountupdate.saldo = myaccount.saldo;
@@ -255,7 +255,9 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
// Calcola Saldo Pendente !
await myaccount.calcPending(true);
return ris;
const recupdated = await Account.findOne({ _id: myaccount.id });
return recupdated;
}
} catch (e) {
@@ -322,8 +324,9 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
});
if (contocom) {
myaccount.fidoConcesso = shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_CONTO_COMUNITARIO;
myaccount.qta_maxConcessa = shared_consts.CIRCUIT_PARAMS.SCOPERTO_MAX_CONTO_COMUNITARIO;
myaccount.fidoConcesso = mycircuit.fido_scoperto_default_contocom || shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_CONTO_COMUNITARIO;
myaccount.qta_maxConcessa = mycircuit.qta_max_default_contocom || shared_consts.CIRCUIT_PARAMS.SCOPERTO_MAX_CONTO_COMUNITARIO;
} else {
if (!mycircuit.fido_scoperto_default_grp)
mycircuit.fido_scoperto_default_grp = shared_consts.CIRCUIT_PARAMS.SCOPERTO_MIN_GRP;
@@ -343,7 +346,13 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
myaccount.fidoConcesso = 0;
}
return await myaccount.save();
let acc = await myaccount.save();
if (mycircuit.creditodiPartenza && mycircuit.creditodiPartenza > 0) {
acc = await Account.addtoSaldo(acc, mycircuit.creditodiPartenza, false);
}
return acc;
}
return myaccount;
@@ -605,8 +614,12 @@ AccountSchema.statics.SetMinMaxPersonali = async function (idapp, fidoConcesso,
}
});
// Se aggiorno questi dati, allora devo aggiornare anche gli account del RIS Nazionale
await Account.updateAccountCircuitoNazionaleByLimiti(idapp, circuitId, fidoConcesso, qta_maxConcessa);
const circuit = await Circuit.findOne({ _id: circuitId });
if (!circuit.circuitoIndipendente) {
// Se aggiorno questi dati, e non è un Circuito Indipendente, allora devo aggiornare anche gli account del RIS Nazionale
await Account.updateAccountCircuitoNazionaleByLimiti(idapp, circuitId, fidoConcesso, qta_maxConcessa);
}
} else {
const ris = await Account.updateMany({ idapp, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
@@ -690,9 +703,9 @@ AccountSchema.statics.updateAccountCircuitoNazionaleByLimiti = async function (i
} catch (e) {
console.error('updateAccountCircuitoNazionaleByLimiti', e);
}
return false;
};
AccountSchema.statics.canEditAccountAdmins = async function (username, id) {
@@ -736,7 +749,7 @@ AccountSchema.statics.removeAdminOfAccount = async function (idapp, username, ci
// Rimuovi l'account
AccountSchema.statics.removeAccount = async function (accountId) {
return await Account.deleteOne({ _id: accountId});
return await Account.deleteOne({ _id: accountId });
};
AccountSchema.statics.updateSaldoAndTransato_AllAccounts = async function (idapp) {

View File

@@ -19,6 +19,9 @@ const CatProdSchema = new Schema({
name: {
type: String,
},
descr_estesa: {
type: String,
},
img: {
type: String,
},

View File

@@ -229,6 +229,22 @@ const CircuitSchema = new Schema({
type: Boolean,
default: false,
},
askManagerToEnter: {
type: Boolean,
default: false,
},
sendEmailAfterAskingToEnter: {
type: Boolean,
default: false,
},
circuitoIndipendente: {
type: Boolean,
default: false,
},
creditodiPartenza: {
type: Number,
default: 0,
},
});
CircuitSchema.pre('save', async function (next) {
@@ -300,8 +316,15 @@ CircuitSchema.statics.getWhatToShow = function (idapp, username) {
qta_max_default: 1,
fido_scoperto_default_grp: 1,
qta_max_default_grp: 1,
fido_scoperto_default_contocom: 1,
qta_max_default_contocom: 1,
deperimento: 1,
showAlways: 1,
ignoreLimits: 1,
askManagerToEnter: 1,
sendEmailAfterAskingToEnter: 1,
circuitoIndipendente: 1,
creditodiPartenza: 1,
transactionsEnabled: 1,
status: 1,
valuta_per_euro: 1,
@@ -359,6 +382,11 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
regulation: 1,
numMembers: 1,
showAlways: 1,
ignoreLimits: 1,
askManagerToEnter: 1,
sendEmailAfterAskingToEnter: 1,
circuitoIndipendente: 1,
creditodiPartenza: 1,
systemUserId: 1,
founderUserId: 1,
nome_valuta: 1,
@@ -367,6 +395,8 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
fido_scoperto_default: 1,
fido_scoperto_default_grp: 1,
qta_max_default_grp: 1,
fido_scoperto_default_contocom: 1,
qta_max_default_contocom: 1,
qta_max_default: 1,
valuta_per_euro: 1,
symbol: 1,
@@ -1093,6 +1123,9 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
totCircolante: 0,
date_created: new Date(),
admins: [{ username: useradmin }],
askManagerToEnter: false,
sendEmailAfterAskingToEnter: false,
circuitoIndipendente: false,
});
myrec = await circ.save();

60
src/server/models/collana.js Executable file
View File

@@ -0,0 +1,60 @@
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 CollanaSchema = new Schema({
idapp: {
type: String,
},
idCollana: {
type: Number,
},
descrizione: {
type: String,
},
Descrizione_Estesa: {
type: String,
},
dataOra: {
type: Date,
},
enabled: {
type: Boolean,
},
enabledAlFresco: {
type: Boolean,
},
});
var Collana = module.exports = mongoose.model('Collana', CollanaSchema);
module.exports.getFieldsForSearch = function () {
return [
{ field: 'descrizione', type: tools.FieldType.string },
]
};
module.exports.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
module.exports.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return await Collana.find(myfind).sort({name: 1, surname: 1});
};
module.exports.createIndexes((err) => {
if (err) throw err;
});

View File

@@ -58,8 +58,11 @@ const catalogo = new Schema(
//++AddCATALOGO_FIELDS
productTypes: [{ type: Number }],
excludeproductTypes: [{ type: Number }],
Editore: [{ type: String }],
sort: { type: Number },
editore: [{ type: String }],
argomenti: [{ type: String }],
idCollana: { type: Number },
sort_field: { type: String },
sort_dir: { type: Number },
pdf: { type: Boolean },
pdf_filename: { type: String },
printable: { type: Boolean },
@@ -282,7 +285,7 @@ MyElemSchema.statics.SetIdPageInsteadThePah = async function (idapp) {
for (const [path, id] of Object.entries(pathToIdMap)) {
if (path) {
await MyElem.updateMany(
{ idapp },
{ idapp },
{ path: path }, // Condizione per aggiornare dove il path corrisponde
{
$set: {
@@ -329,7 +332,7 @@ MyElemSchema.statics.SetIdPageInsteadThePah = async function (idapp) {
for (const [oldpath, id] of Object.entries(pathToIdMap2)) {
await MyElem.updateMany(
{ idapp },
{ idapp },
{ oldpath: oldpath }, // Condizione per aggiornare dove il path corrisponde
{
$set: { idPage: id }
@@ -358,7 +361,7 @@ MyElemSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
const arrrec = await MyElem.find(myfind).sort({ order: 1 });
const arrrec = await MyElem.find(myfind).lean().sort({ order: 1 });
return arrrec;
};
@@ -368,32 +371,68 @@ MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {
try {
const ris = await MyElem.find({ idapp });
const ris = await MyElem.find({ idapp }).lean();
// Estrai le schede che hanno isTemplate = true
const schedeTemplate = ris.flatMap(elem =>
elem.catalogo && elem.catalogo.arrSchede ? elem.catalogo.arrSchede.filter(scheda => scheda.scheda?.isTemplate) : []
elem.catalogo && elem.catalogo.arrSchede ?
elem.catalogo.arrSchede
.filter(scheda => scheda.scheda?.isTemplate)
.map(scheda => ({
...scheda, // mantieni i dati originali della scheda
idPageOrig: elem.idPage // aggiungi l'idPage
}))
: []
);
/*
// Trova tutti i documenti in cui idapp corrisponde e contiene schede con isTemplate = true
const ris = await MyElem.find(
{ idapp },
{ 'catalogo.arrSchede': { $elemMatch: { isTemplate: true } } }
).populate('catalogo.arrSchede');
// Estrai solo le schede che hanno isTemplate = true
const schedeTemplate = ris.flatMap(elem =>
elem.catalogo.arrSchede.filter(scheda => scheda.isTemplate)
);
*/
return schedeTemplate;
} catch (e) {
console.error('Err', e);
}
};
// Ricerca tra tutte le schede, contenute in catalogo, se esiste un nome di template uguale,
// se non lo trova allora è quello giusto per crearne uno nuovo
MyElemSchema.statics.getNewFreeNameTemplate = async function (idapp, idPageOrig, nomeTemplate) {
const MyElem = this;
try {
const ris = await MyElem.find(
{
idapp,
'catalogo.arrSchede.scheda.isTemplate': true,
'catalogo.arrSchede.scheda.idPage': { $ne: idPageOrig }
},
{
'catalogo.arrSchede.scheda.name': 1,
'catalogo.arrSchede.scheda.isTemplate': 1,
'catalogo.arrSchede.scheda.idPage': 1
});
const existingNames = new Set(
ris.flatMap(elem =>
elem.catalogo?.arrSchede?.filter(scheda =>
scheda.scheda?.isTemplate &&
scheda.scheda?.idPage !== idPageOrig
)
.map(scheda => scheda.scheda?.name) || []
)
);
let ind = 2;
let newNameTemplate;
do {
newNameTemplate = `${nomeTemplate}_copia_${ind}`;
ind++;
} while (existingNames.has(newNameTemplate) && ind <= 1000);
return newNameTemplate;
} catch (e) {
console.error('Err', e);
throw e; // Propagate the error
}
};
const MyElem = mongoose.model('MyElem', MyElemSchema);
MyElem.createIndexes((err) => {

View File

@@ -129,8 +129,11 @@ const scheletroScheda = {
productTypes: [{ type: Number }],
excludeproductTypes: [{ type: Number }],
editore: [{ type: String }],
argomenti: [{ type: String }],
idCollana: { type: Number },
author: { type: String },
sort: { type: Number },
sort_field: { type: String },
sort_dir: { type: Number },
arrProdottiSpeciali: [{ type: String }],
};
@@ -149,11 +152,7 @@ MySchedaSchema.statics.executeQueryTable = function (idapp, params, user) {
};
MySchedaSchema.statics.findAllIdApp = async function (idapp) {
const MyScheda = this;
const myfind = { idapp };
return await MyScheda.find(myfind);
};
const MyScheda = mongoose.model('MyScheda', MySchedaSchema);

View File

@@ -119,6 +119,7 @@ const productInfoSchema = new Schema({
type: String,
},
idAuthors: [{ type: Schema.Types.ObjectId, ref: 'Author' }],
idCollana: { type: Schema.Types.ObjectId, ref: 'Collana' },
idPublisher: { type: Schema.Types.ObjectId, ref: 'Publisher' },
collezione: {
type: String,
@@ -138,7 +139,9 @@ const productInfoSchema = new Schema({
},
totVen: Number,
totFat: Number,
vLast3M: Number,
fatLast3M: Number,
vLast6M: Number,
vLastY: Number,
vLast2Y: Number,
@@ -218,6 +221,14 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
as: 'authors'
}
},
{
$lookup: {
from: 'collanas',
localField: 'idCollana',
foreignField: '_id',
as: 'collana'
}
},
{
$lookup: {
from: 'publishers',

View File

@@ -402,6 +402,8 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
destinatario += ' (' + username_mittente + ')'
}
const circuit = await Circuit.findOne({ name: circuitname });
if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC) {
newdescr = i18n.__('CIRCUIT_CREATED', sender, recnotif.paramsObj.circuitnameDest);
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SETFIDO) {
@@ -470,7 +472,12 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
} else {
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', sender, '<strong>' + recnotif.paramsObj.circuitnameDest + '</strong>', numuserincircuit, aportador_solidario);
if (circuit.askManagerToEnter)
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER_ASKMANAGER', sender, '<strong>' + recnotif.paramsObj.circuitnameDest + '</strong>', numuserincircuit, aportador_solidario);
}
const myadmins = await Circuit.getListAdmins(recnotif.idapp, recnotif.paramsObj.circuitnameDest);
recnotif.textaddTelegram += '\n' + i18n.__('CIRCUIT_ADMINS', myadmins.num, myadmins.str);
recnotif.textaddTelegram += '\n' + i18n.__('CIRCUIT_WHERE_IS_PRESENT', await Circuit.getListCircuitsByUsername(recnotif.idapp, sender, recnotif.extrarec.groupname));

View File

@@ -22,6 +22,9 @@ const SubCatProdSchema = new Schema({
name: {
type: String,
},
descr_estesa: {
type: String,
},
img: {
type: String,
},

View File

@@ -3014,6 +3014,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
}
} else if (cmd === shared_consts.CIRCUITCMD.SET) {
if (groupname) {
const foundIfCircuitInGroup = await MyGroup.ifCircuitAlreadyInGroup(idapp, groupname, circuitname);
@@ -3044,6 +3045,10 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
};
ris = await User.updateOne({ idapp, username: usernameOrig }, update);
// Elimina la richiesta:
update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } };
await Circuit.updateOne({ idapp, name: circuitname }, update);
// Elimina eventualmente se era bloccato:
update = { $pull: { refused_users: { username: { $in: [usernameOrig] } } } };
await Circuit.updateOne({ idapp, name: circuitname }, update);
@@ -3138,9 +3143,16 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
},
});
const thiscircuit = await Circuit.findOne({
idapp,
name: circuitname,
});
if (value) {
// Aggiungi intanto l'utente al Circuito (senza fido)
ris = await this.addCircuitToUser(idapp, usernameOrig, circuitname, false);
if (!thiscircuit.askManagerToEnter) {
// Aggiungi intanto l'utente al Circuito (senza fido)
ris = await this.addCircuitToUser(idapp, usernameOrig, circuitname, false);
}
if (!foundIfAlreadyAskCircuit) {
update = {
@@ -3151,10 +3163,11 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
},
},
};
// Aggiungi la richiesta per ottenere il fido
// Aggiungi la richiesta per ottenere il fido (o per entrare nel circuito)
ris = await Circuit.updateOne({ idapp, name: circuitname }, update);
}
if (ris) {
// Invia una notifica alla persona
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, true, true, username_action, extrarec);