ver 0.5.71:

- Info Conto
- Admin: poter modificare Fido e QtaMax.
This commit is contained in:
Surya Paolo
2023-02-23 16:07:43 +01:00
parent 0076adac76
commit 84ceed500d
5 changed files with 470 additions and 221 deletions

View File

@@ -82,5 +82,8 @@
"CIRCUIT_COINS_ALREADY_PROCESSED": "La richiesta è stata già processata. Stato %s",
"STATUS_SENT": "Inviato",
"STATUS_REFUSED": "Rifiutato",
"SALDO_VARIATO": "[Circuito %s] l'utente %s ha variato il Saldo di %s da %s a %s %s",
"FIDOCONCESSO_VARIATO": "[Circuito %s] l'utente %s ha variato il Fido Concesso di %s da %s a %s %s",
"QTAMAX_VARIATO": "[Circuito %s] l'utente %s ha variato la quantità massima concessa di %s da %s a %s %s",
"CLICCA_QUI": "CLICCA QUI"
}

View File

@@ -0,0 +1,98 @@
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
const tools = require('../tools/general');
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;
});
const UserRequestSchema = new Schema({
_id: {
type: Number,
},
idapp: {
type: String,
},
typeReq: {
type: Number,
},
valueRequested: {
type: Number,
},
strRequested: {
type: String,
},
username: {
type: String,
},
groupname: {
type: String,
},
note: {
type: String,
},
createdBy: {
type: String,
},
date_created: {
type: Date,
},
date_updated: {
type: Date,
},
deleted: {
type: Boolean,
default: false,
},
processed: {
type: Boolean,
default: false,
},
username_answered: {
type: String,
},
state_requested: {
type: Number,
},
msgout_answered: {
type: String,
},
});
UserRequestSchema.statics.getFieldsForSearch = function () {
return [{ field: 'descr', type: tools.FieldType.string }];
};
UserRequestSchema.statics.executeQueryTable = function (idapp, params, user) {
params.fieldsearch = this.getFieldsForSearch();
const { User } = require('./user');
return tools.executeQueryTable(this, idapp, params, user);
};
UserRequestSchema.pre('save', async function (next) {
if (this.isNew) {
this.date_created = new Date();
}
next();
});
UserRequestSchema.statics.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return await UserRequest.find(myfind);
};
const UserRequest = mongoose.model('UserRequest', UserRequestSchema);
module.exports = { UserRequest };

View File

@@ -5,6 +5,8 @@ const router = express.Router(),
const telegrambot = require('../telegram/telegrambot');
const i18n = require('i18n');
const sharp = require('sharp');
const { authenticate, authenticate_noerror } = require(
@@ -475,7 +477,7 @@ router.post('/settable', authenticate, async (req, res) => {
return res.send({ rec: myrec, ris });
});
// aggiungi il creatore al Circuito stesso
// aggiungi il creatore al Circuito stesso
return await User.setCircuitCmd(mydata.idapp, req.user.username, myrec.name,
shared_consts.CIRCUITCMD.SET, true, req.user.username, extrarec).then((ris) => {
return res.send({ rec: myrec, ris });
@@ -839,6 +841,12 @@ router.patch('/chval', authenticate, async (req, res) => {
}
let precRec = null
if (mydata.table === 'accounts') {
precRec = await mytable.findById(id);
}
return await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }).
then(async (rec) => {
// tools.mylogshow(' REC TO MODIFY: ', rec);
@@ -865,12 +873,27 @@ router.patch('/chval', authenticate, async (req, res) => {
}
if (mydata.table === 'accounts') {
let msg = '';
if (rec.circuitId)
circuit = await Circuit.getCircuitByCircuitId(rec.circuitId);
let dest = rec.groupname ? rec.groupname : rec.username;
let valprec = 0
if ('saldo' in fieldsvalue) {
let circuito = '';
if (rec.circuitId)
circuit = await Circuit.getCircuitByCircuitId(rec.circuitId);
msg = '[' + circuit.name + '] l\'utente ' + req.user.username + ' ha variato il Saldo di ' + rec.username + ' a ' + fieldsvalue.saldo + ' ' + circuit.symbol;
valprec = precRec && precRec.saldo ? precRec.saldo : 0
msg = i18n.__('SALDO_VARIATO', circuit.name, req.user.username, dest, valprec, fieldsvalue.saldo, circuit.symbol);
} else if ('fidoConcesso' in fieldsvalue) {
valprec = precRec && precRec.fidoConcesso ? precRec.fidoConcesso : 0
msg = i18n.__('FIDOCONCESSO_VARIATO', circuit.name, req.user.username, dest, valprec, fieldsvalue.fidoConcesso, circuit.symbol);
} else if ('qta_maxConcessa' in fieldsvalue) {
valprec = precRec && precRec.qta_maxConcessa ? precRec.qta_maxConcessa : 0
msg = i18n.__('QTAMAX_VARIATO', circuit.name, req.user.username, dest, valprec, fieldsvalue.qta_maxConcessa, circuit.symbol);
}
if (msg) {
telegrambot.sendMsgTelegramToTheManagers(idapp, msg);
telegrambot.sendMsgTelegramToTheAdminsOfCircuit(idapp, circuit.path, msg);
}
}

View File

@@ -0,0 +1,99 @@
const express = require('express');
const router = express.Router();
const tools = require('../tools/general');
const server_constants = require('../tools/server_constants');
const { authenticate } = require('../middleware/authenticate');
const mongoose = require('mongoose').set('debug', false);
const { User } = require('../models/user');
const { MyGroup } = require('../models/mygroup');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
async function getGroupRecAdminsInfo(idapp, data) {
if (data && data.admins) {
for (const admin of data.admins) {
const myuser = await User.findOne({ idapp, username: admin.username }, { 'profile.img': 1 }).lean();
admin.profile = { img: myuser.profile.img };
}
}
return data;
}
router.post('/load', authenticate, async (req, res) => {
const idapp = req.body.idapp;
const groupname = req.body.groupname;
const usernameOrig = req.user.username;
try {
const { SendNotif } = require('../models/sendnotif');
const { Circuit } = require('../models/circuit');
const { Account } = require('../models/account');
// Check if ìs a Notif to read
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
const whatshow = MyGroup.getWhatToShow(idapp, req.user.username);
let data = await MyGroup.findOne({ idapp, groupname }, whatshow).lean();
/*
if (data.mycircuits) {
for (let i = 0; i < data.mycircuits.length; i++) {
const mycirc = await Circuit.findOne({ idapp, name: data.mycircuits[i].circuitname }).lean();
data.mycircuits[i] = mycirc;
}
}
*/
if (data.mycircuits) {
for (let i = 0; i < data.mycircuits.length; i++) {
const mycirc = await Circuit.findOne({ idapp, name: data.mycircuits[i].circuitname }).lean();
if (mycirc)
data.mycircuits[i].account = await Account.getAccountByUsernameAndCircuitId(idapp, '', mycirc._id, true, groupname);
}
}
let cities = [];
if (data) {
cities = await MyGroup.extractCitiesName(idapp, data._id);
if (cities && cities.length > 0) {
cities = cities[0].mycities;
}
}
data = await getGroupRecAdminsInfo(idapp, data);
const whatshowUsers = await User.getWhatToShow_IfFriends(idapp, req.user.username);
const users_in_group = await User.find(
{
idapp,
'profile.mygroups': {
$elemMatch: { groupname: { $eq: groupname } },
},
},
whatshowUsers,
).lean();
res.send({ mygroup: data, users_in_group, cities });
} catch (e) {
console.error('Error in MyGroups', e);
return res.status(400).send(e);
}
const ris = null;
});
module.exports = router;

View File

@@ -1032,247 +1032,273 @@ const MyTelegramBot = {
},
sendMsgTelegramToTheManagersAndZoomeri: async function (
idapp, text, onlyintofile, MyForm = null) {
sendMsgTelegramToTheAdminsOfCircuit: async function (
idapp, circuitpath, text, onlyintofile = false, MyForm = null, nottousername = '') {
tools.writeManagersLog(text);
if (!onlyintofile) {
// const usersmanagers = await User.getusersManagersAndZoomeri(idapp);
const usersmanagers = await User.getusersManagers(idapp);
if (usersmanagers) {
for (const rec of usersmanagers) {
await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id,
emo.ROBOT_FACE + ': ' + text, undefined, undefined, true, MyForm);
await tools.snooze(100);
}
}
}
return true;
},
getMsgByTipoMsg: async function (mydata, lang, user, sonosognatore) {
if (!!mydata.msgextra) {
return { body: mydata.msgextra, title: '' };
}
let title = '';
let msg = '';
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
if (sonosognatore)
msg = printf(tools.gettranslate('SEND_LINK_CHAT_SOGNATORE', lang),
user.name,
mydata.navemediatore.riga + '.' + mydata.navemediatore.col,
mydata.msgpar1);
else
msg = printf(tools.gettranslate('SEND_LINK_CHAT_DONATORI', lang),
user.name,
mydata.navemediatore.riga + '.' + mydata.navemediatore.col,
mydata.msgpar1);
} else if (mydata.tipomsg === tools.TipoMsg.SEND_MSG || mydata.tipomsg ===
tools.TipoMsg.SEND_MSG_SINGOLO) {
if (!!mydata.username_mitt) {
msg = '[' + tools.gettranslate('MSG_SEND_FROM', lang) + ' ' +
mydata.username_mitt + ']:' + tools.ACAPO;
}
msg += mydata.msgpar1;
} else if (mydata.tipomsg >= 1000) {
const ris = await MsgTemplate.getMsgByLang(user.idapp, user, mydata.tipomsg,
lang);
msg = ris.body;
title = ris.title;
}
const cl = getclTelegByidapp(user.idapp);
if (cl) {
msg = await tools.convertSpecialTags(rec.user, msg);
}
if (!!mydata.flotta) {
// SOSTITUISCI LE PAROLE CHIAVI
if (!!mydata.flotta.date_start)
msg = msg.replace('{date_start}',
tools.getstrDateLongTot(new Date(mydata.flotta.date_start),
user.lang));
if (!!mydata.flotta.date_close)
msg = msg.replace('{date_close}',
tools.getstrDateLongTot(new Date(mydata.flotta.date_close),
user.lang));
if (!!mydata.flotta.link_superchat)
msg = msg.replace('{link_superchat}', mydata.flotta.link_superchat);
if (!!mydata.flotta.tutor1)
msg = msg.replace('{tutor1}', mydata.flotta.tutor1);
if (!!mydata.flotta.tutor2)
msg = msg.replace('{tutor2}', mydata.flotta.tutor2);
if (!!mydata.flotta.tutor3)
msg = msg.replace('{tutor3}', mydata.flotta.tutor3);
if (!!mydata.flotta.tutorslo)
msg = msg.replace('{tutorslo}', mydata.flotta.tutorslo);
if (!!mydata.flotta.sognatore_nomecognome)
msg = msg.replace('{sognatore}', mydata.flotta.sognatore_nomecognome);
if (!!mydata.flotta.sognatore_nomecognome)
msg = msg.replace('{flotta}',
mydata.flotta.riga + '.' + Math.ceil(mydata.flotta.col_prima / 8) +
' - ' + mydata.flotta.riga + '.' +
Math.ceil(mydata.flotta.col_ultima / 8));
}
return { body: msg, title };
},
sendMsgTelegramToTheAdminAllSites: async function (text, senzaintestazione) {
for (const idapp of this.getAppTelegram()) {
text = text.replace('{appname}', tools.getNomeAppByIdApp(idapp));
await this.sendMsgTelegramToTheAdmin(idapp, text, senzaintestazione);
}
},
sendMsgTelegramToTheAdmin: async function (idapp, text, senzaintestazione) {
const usersmanagers = await User.getusersManagers(idapp);
let intestaz = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': ';
if (senzaintestazione)
intestaz = '';
tools.writeManagersLog(text);
let teleg_id = 0;
if (!onlyintofile) {
const usersmanagers = await Circuit.getListAdminsByCircuitPath(idapp, circuitpath);
if (usersmanagers) {
for (const rec of usersmanagers) {
if (User.isAdmin(rec.perm)) {
this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id,
intestaz + text, undefined, undefined, true);
await tools.snooze(300);
if (rec.username !== nottousername) {
teleg_id = await User.TelegIdByUsername(idapp, rec.username);
if (teleg_id) {
await this.sendMsgTelegramByIdTelegram(idapp, teleg_id,
emo.ROBOT_FACE + ': ' + text, undefined, undefined, true,
MyForm);
await tools.snooze(100);
}
}
}
}
return true;
}
return true;
},
},
sendMsgTelegramToALL: async function (idapp, text) {
const usersall = await User.getUsersTelegALL(idapp);
sendMsgTelegramToTheManagersAndZoomeri: async function (
idapp, text, onlyintofile, MyForm = null) {
if (usersall) {
for (const rec of usersall) {
this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, text);
tools.writeManagersLog(text);
if (!onlyintofile) {
// const usersmanagers = await User.getusersManagersAndZoomeri(idapp);
const usersmanagers = await User.getusersManagers(idapp);
if (usersmanagers) {
for (const rec of usersmanagers) {
await this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id,
emo.ROBOT_FACE + ': ' + text, undefined, undefined, true, MyForm);
await tools.snooze(100);
}
}
}
return true;
},
getMsgByTipoMsg: async function (mydata, lang, user, sonosognatore) {
if (!!mydata.msgextra) {
return { body: mydata.msgextra, title: '' };
}
let title = '';
let msg = '';
if (mydata.tipomsg === tools.TipoMsg.SEND_LINK_CHAT_DONATORI) {
if (sonosognatore)
msg = printf(tools.gettranslate('SEND_LINK_CHAT_SOGNATORE', lang),
user.name,
mydata.navemediatore.riga + '.' + mydata.navemediatore.col,
mydata.msgpar1);
else
msg = printf(tools.gettranslate('SEND_LINK_CHAT_DONATORI', lang),
user.name,
mydata.navemediatore.riga + '.' + mydata.navemediatore.col,
mydata.msgpar1);
} else if (mydata.tipomsg === tools.TipoMsg.SEND_MSG || mydata.tipomsg ===
tools.TipoMsg.SEND_MSG_SINGOLO) {
if (!!mydata.username_mitt) {
msg = '[' + tools.gettranslate('MSG_SEND_FROM', lang) + ' ' +
mydata.username_mitt + ']:' + tools.ACAPO;
}
msg += mydata.msgpar1;
} else if (mydata.tipomsg >= 1000) {
const ris = await MsgTemplate.getMsgByLang(user.idapp, user, mydata.tipomsg,
lang);
msg = ris.body;
title = ris.title;
}
const cl = getclTelegByidapp(user.idapp);
if (cl) {
msg = await tools.convertSpecialTags(rec.user, msg);
}
if (!!mydata.flotta) {
// SOSTITUISCI LE PAROLE CHIAVI
if (!!mydata.flotta.date_start)
msg = msg.replace('{date_start}',
tools.getstrDateLongTot(new Date(mydata.flotta.date_start),
user.lang));
if (!!mydata.flotta.date_close)
msg = msg.replace('{date_close}',
tools.getstrDateLongTot(new Date(mydata.flotta.date_close),
user.lang));
if (!!mydata.flotta.link_superchat)
msg = msg.replace('{link_superchat}', mydata.flotta.link_superchat);
if (!!mydata.flotta.tutor1)
msg = msg.replace('{tutor1}', mydata.flotta.tutor1);
if (!!mydata.flotta.tutor2)
msg = msg.replace('{tutor2}', mydata.flotta.tutor2);
if (!!mydata.flotta.tutor3)
msg = msg.replace('{tutor3}', mydata.flotta.tutor3);
if (!!mydata.flotta.tutorslo)
msg = msg.replace('{tutorslo}', mydata.flotta.tutorslo);
if (!!mydata.flotta.sognatore_nomecognome)
msg = msg.replace('{sognatore}', mydata.flotta.sognatore_nomecognome);
if (!!mydata.flotta.sognatore_nomecognome)
msg = msg.replace('{flotta}',
mydata.flotta.riga + '.' + Math.ceil(mydata.flotta.col_prima / 8) +
' - ' + mydata.flotta.riga + '.' +
Math.ceil(mydata.flotta.col_ultima / 8));
}
return { body: msg, title };
},
sendMsgTelegramToTheAdminAllSites: async function (text, senzaintestazione) {
for (const idapp of this.getAppTelegram()) {
text = text.replace('{appname}', tools.getNomeAppByIdApp(idapp));
await this.sendMsgTelegramToTheAdmin(idapp, text, senzaintestazione);
}
},
sendMsgTelegramToTheAdmin: async function (idapp, text, senzaintestazione) {
const usersmanagers = await User.getusersManagers(idapp);
let intestaz = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': ';
if (senzaintestazione)
intestaz = '';
if (usersmanagers) {
for (const rec of usersmanagers) {
if (User.isAdmin(rec.perm)) {
this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id,
intestaz + text, undefined, undefined, true);
await tools.snooze(300);
}
}
}
return true;
},
},
sendMsgTelegram: async function (
idapp, username, text, alsotomanagers = false, username_mitt = '') {
const { User } = require('../models/user');
sendMsgTelegramToALL: async function (idapp, text) {
const usersall = await User.getUsersTelegALL(idapp);
const teleg_id = await User.TelegIdByUsername(idapp, username);
const cl = getclTelegByidapp(idapp);
let ris = null;
if (cl && teleg_id) {
ris = await cl.sendMsg(teleg_id, text);
if (usersall) {
for (const rec of usersall) {
this.sendMsgTelegramByIdTelegram(idapp, rec.profile.teleg_id, text);
await tools.snooze(300);
}
}
},
sendMsgTelegram: async function (
idapp, username, text, alsotomanagers = false, username_mitt = '') {
const { User } = require('../models/user');
const teleg_id = await User.TelegIdByUsername(idapp, username);
const cl = getclTelegByidapp(idapp);
let ris = null;
if (cl && teleg_id) {
ris = await cl.sendMsg(teleg_id, text);
}
if (cl && teleg_id) {
if (alsotomanagers) {
await this.sendMsgTelegramToTheManagers(idapp, text);
}
if (!!username_mitt) {
const rec = cl.getRecByUsername(username);
if (rec) {
rec.msgall_username_specifico = username_mitt;
}
}
}
return ris;
},
sendMsgTelegramByIdTelegram: async function (
idapp, idtelegram, text, message_id, chat_id, ripr_menuPrec,
MyForm = null) {
console.log('sendMsgTelegramByIdTelegram', text);
if (!idtelegram)
return;
const cl = getclTelegByidapp(idapp);
if (cl && idtelegram) {
let myform = null;
return await cl.sendMsg(idtelegram, text, null, MyForm, message_id,
chat_id, ripr_menuPrec);
}
},
reloadMenuBot: async function (idapp) {
const cl = getclTelegByidapp(idapp);
if (cl) {
return cl.updateMenuBot();
}
},
reloadSites: async function () {
tools.loadApps();
},
sendMsgFromSite: async function (idapp, user, params) {
try {
let ris = {
numrec: 0,
nummsgsent: 0,
text: '',
};
let invia = false;
let content = '';
let tipomsgtempl = 0;
params.sendreally = true;
if (params.typemsg === shared_consts.TypeMsg.SEND_TO_MYSELF) {
params.usernameDest = user.username;
}
if (cl && teleg_id) {
if (alsotomanagers) {
await this.sendMsgTelegramToTheManagers(idapp, text);
}
if (!!username_mitt) {
const rec = cl.getRecByUsername(username);
if (rec) {
rec.msgall_username_specifico = username_mitt;
}
}
if (params.cmd === shared_consts.MsgTeleg.SHARE_MSGREG) {
tipomsgtempl = shared_consts.TypeMsgTemplate.MS_SHARE_LINK;
invia = true;
} else if (params.cmd === shared_consts.MsgTeleg.SHARE_TEXT) {
invia = !!params.content;
}
if (tipomsgtempl > 0) {
const rismsg = await MsgTemplate.getMsgByLang(idapp, user, tipomsgtempl, user.lang);
params.content = rismsg.body;
params.title = rismsg.title;
}
if (invia) {
ris = await globalTables.SendMsgToParam(idapp, params);
}
return ris;
},
sendMsgTelegramByIdTelegram: async function (
idapp, idtelegram, text, message_id, chat_id, ripr_menuPrec,
MyForm = null) {
} catch (e) {
console.error('sendMsgFromSite', e);
}
},
console.log('sendMsgTelegramByIdTelegram', text);
sendMsgFromSiteToBotTelegram: async function (idapp, user, params) {
if (!idtelegram)
return;
if (!params.typesend) {
params.typesend = shared_consts.TypeSend.TELEGRAM;
}
const cl = getclTelegByidapp(idapp);
if (cl && idtelegram) {
let myform = null;
return this.sendMsgFromSite(idapp, user, params);
return await cl.sendMsg(idtelegram, text, null, MyForm, message_id,
chat_id, ripr_menuPrec);
}
},
reloadMenuBot: async function (idapp) {
const cl = getclTelegByidapp(idapp);
if (cl) {
return cl.updateMenuBot();
}
},
reloadSites: async function () {
tools.loadApps();
},
sendMsgFromSite: async function (idapp, user, params) {
try {
let ris = {
numrec: 0,
nummsgsent: 0,
text: '',
};
let invia = false;
let content = '';
let tipomsgtempl = 0;
params.sendreally = true;
if (params.typemsg === shared_consts.TypeMsg.SEND_TO_MYSELF) {
params.usernameDest = user.username;
}
if (params.cmd === shared_consts.MsgTeleg.SHARE_MSGREG) {
tipomsgtempl = shared_consts.TypeMsgTemplate.MS_SHARE_LINK;
invia = true;
} else if (params.cmd === shared_consts.MsgTeleg.SHARE_TEXT) {
invia = !!params.content;
}
if (tipomsgtempl > 0) {
const rismsg = await MsgTemplate.getMsgByLang(idapp, user, tipomsgtempl, user.lang);
params.content = rismsg.body;
params.title = rismsg.title;
}
if (invia) {
ris = await globalTables.SendMsgToParam(idapp, params);
}
return ris;
} catch (e) {
console.error('sendMsgFromSite', e);
}
},
sendMsgFromSiteToBotTelegram: async function (idapp, user, params) {
if (!params.typesend) {
params.typesend = shared_consts.TypeSend.TELEGRAM;
}
return this.sendMsgFromSite(idapp, user, params);
},
},
};