Visu Sent Monete

This commit is contained in:
Paolo Arena
2022-09-13 12:28:49 +02:00
parent ef1bd2e138
commit 2f24a02a63
6 changed files with 205 additions and 78 deletions

View File

@@ -114,6 +114,17 @@ sendNotifSchema.statics.setNotifAsRead = function(idapp, username, idnotif) {
}
};
sendNotifSchema.statics.getRecNotif = function(id) {
const SendNotif = this;
try {
return SendNotif.findById(id).lean();
}catch (e) {
return null;
}
};
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function(username, lastdataread, idapp) {
const SendNotif = this;
@@ -259,7 +270,8 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
newdescr = i18n.__('CIRCUIT_CREATED', userorig, recnotif.paramsObj.circuitnameDest);
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
if (recnotif.paramsObj.isAdmin) {
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
newdescr = i18n.__('ACCETTATO_NOTIFICA_ADMINS_CIRCUIT', userorig, recnotif.paramsObj.circuitnameDest,
recnotif.paramsObj.username_action);
recnotif.openUrl = '/my/' + userorig;
} else {
newdescr = i18n.__('CIRCUIT_ACCEPTED', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.username_action);
@@ -286,7 +298,8 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
}
tag = 'refcircuit';
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER) {
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest, recnotif.paramsObj.singleadmin_username);
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', userorig, recnotif.paramsObj.circuitnameDest,
recnotif.paramsObj.singleadmin_username);
tag = 'reqcircuits';
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_DELETE_USER) {
@@ -309,11 +322,13 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = function(recnotif) {
}
tag = 'removeadmincircuit';
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ) {
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ', recnotif.paramsObj.username_action, recnotif.paramsObj.extrarec.qty, recnotif.paramsObj.extrarec.symbol);
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ', recnotif.paramsObj.username_action, recnotif.paramsObj.extrarec.qty.toString(),
recnotif.paramsObj.extrarec.symbol);
tag = 'sendcoin';
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) {
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED', recnotif.paramsObj.extrarec.qty, recnotif.paramsObj.extrarec.symbol, recnotif.paramsObj.username_action);
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED', recnotif.paramsObj.extrarec.qty.toString(), recnotif.paramsObj.extrarec.symbol,
recnotif.paramsObj.username_action);
tag = 'sendcoin';
}
}
@@ -402,7 +417,7 @@ sendNotifSchema.statics.saveAndSendNotif = async function(myrecnotif, req, res,
return await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
}
} catch(e) {
} catch (e) {
console.log(e.message);
return null;
}
@@ -423,6 +438,7 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
}
let newstatus = 0;
let idnotiftosearch = '';
let typeidsearch = 0;
let dest = '';
@@ -453,6 +469,7 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
newstatus = shared_consts.GroupsNotifs.STATUS_GROUPS_DELETED;
}
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
idnotiftosearch = myrecnotif.paramsObj.extrarec.notifId;
typeidsearch = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
dest = myrecnotif.dest;
if (myrecnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
@@ -483,7 +500,7 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
descr: myrecnotif.descr,
};
const query = {
let query = {
idapp: myrecnotif.idapp,
typedir: myrecnotif.typedir,
typeid: typeidsearch,
@@ -492,6 +509,13 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
status: 0,
};
if (idnotiftosearch) {
query = {
_id: idnotiftosearch,
status: 0,
};
}
// Cerca il record e se lo trova lo aggiorna
const myrec = await SendNotif.findOneAndUpdate(query, {$set: fields_to_update}, {
new: true,
@@ -516,11 +540,43 @@ sendNotifSchema.statics.updateStatusAndDescr = async function(myrecnotif, onlysa
};
sendNotifSchema.statics.getStatus = async function(notifId) {
const SendNotif = this;
try {
return await SendNotif.findOne({_id: notifId}, {status: 1}).lean().then((rec) => rec.status);
} catch (e) {
return 0;
}
};
sendNotifSchema.statics.checkIfCoinsAlreadySent = async function(notifId) {
const SendNotif = this;
try {
const status = await SendNotif.getStatus(notifId);
if (status !== null) {
return (status === shared_consts.CircuitsNotif.STATUS_ACCEPTED) ||
(status === shared_consts.CircuitsNotif.STATUS_REFUSED);
}
return true;
} catch (e) {
// If Error, don't send the coins
return true;
}
};
sendNotifSchema.statics.saveNotif = async function(myrecnotif) {
const SendNotif = this;
const {myrecout, save} = await SendNotif.updateStatusAndDescr(myrecnotif, true);
const {myrecout, save} = await SendNotif.updateStatusAndDescr(myrecnotif, true);
if (!myrecout)
return null;
@@ -734,7 +790,9 @@ sendNotifSchema.statics.sendToSingleUserDest = async function(myrecnotif, req, r
try {
myrecnotif.dest = myrecnotif.paramsObj && myrecnotif.paramsObj.usernameDest ? myrecnotif.paramsObj.usernameDest : '';
myrecnotif.username_worked = myrecnotif.paramsObj && myrecnotif.paramsObj.username_worked ? myrecnotif.paramsObj.username_worked : myrecnotif.dest;
myrecnotif.username_worked = myrecnotif.paramsObj && myrecnotif.paramsObj.username_worked
? myrecnotif.paramsObj.username_worked
: myrecnotif.dest;
if (onlysave) {
await SendNotif.saveNotif(myrecnotif);