ver 0.5.71:
- Info Conto - Admin: poter modificare Fido e QtaMax.
This commit is contained in:
@@ -82,5 +82,8 @@
|
|||||||
"CIRCUIT_COINS_ALREADY_PROCESSED": "La richiesta è stata già processata. Stato %s",
|
"CIRCUIT_COINS_ALREADY_PROCESSED": "La richiesta è stata già processata. Stato %s",
|
||||||
"STATUS_SENT": "Inviato",
|
"STATUS_SENT": "Inviato",
|
||||||
"STATUS_REFUSED": "Rifiutato",
|
"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"
|
"CLICCA_QUI": "CLICCA QUI"
|
||||||
}
|
}
|
||||||
98
src/server/models/userrequest.js
Executable file
98
src/server/models/userrequest.js
Executable 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 };
|
||||||
@@ -5,6 +5,8 @@ const router = express.Router(),
|
|||||||
|
|
||||||
const telegrambot = require('../telegram/telegrambot');
|
const telegrambot = require('../telegram/telegrambot');
|
||||||
|
|
||||||
|
const i18n = require('i18n');
|
||||||
|
|
||||||
const sharp = require('sharp');
|
const sharp = require('sharp');
|
||||||
|
|
||||||
const { authenticate, authenticate_noerror } = require(
|
const { authenticate, authenticate_noerror } = require(
|
||||||
@@ -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 }).
|
return await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }).
|
||||||
then(async (rec) => {
|
then(async (rec) => {
|
||||||
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
||||||
@@ -865,12 +873,27 @@ router.patch('/chval', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mydata.table === 'accounts') {
|
if (mydata.table === 'accounts') {
|
||||||
if ('saldo' in fieldsvalue) {
|
let msg = '';
|
||||||
let circuito = '';
|
|
||||||
if (rec.circuitId)
|
if (rec.circuitId)
|
||||||
circuit = await Circuit.getCircuitByCircuitId(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;
|
|
||||||
|
let dest = rec.groupname ? rec.groupname : rec.username;
|
||||||
|
let valprec = 0
|
||||||
|
|
||||||
|
if ('saldo' in fieldsvalue) {
|
||||||
|
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.sendMsgTelegramToTheManagers(idapp, msg);
|
||||||
|
telegrambot.sendMsgTelegramToTheAdminsOfCircuit(idapp, circuit.path, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
99
src/server/router/userrequest_router.js
Executable file
99
src/server/router/userrequest_router.js
Executable 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;
|
||||||
@@ -1032,7 +1032,33 @@ const MyTelegramBot = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMsgTelegramToTheManagersAndZoomeri: async function (
|
sendMsgTelegramToTheAdminsOfCircuit: async function (
|
||||||
|
idapp, circuitpath, text, onlyintofile = false, MyForm = null, nottousername = '') {
|
||||||
|
|
||||||
|
tools.writeManagersLog(text);
|
||||||
|
let teleg_id = 0;
|
||||||
|
|
||||||
|
if (!onlyintofile) {
|
||||||
|
const usersmanagers = await Circuit.getListAdminsByCircuitPath(idapp, circuitpath);
|
||||||
|
if (usersmanagers) {
|
||||||
|
for (const rec of usersmanagers) {
|
||||||
|
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;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
sendMsgTelegramToTheManagersAndZoomeri: async function (
|
||||||
idapp, text, onlyintofile, MyForm = null) {
|
idapp, text, onlyintofile, MyForm = null) {
|
||||||
|
|
||||||
tools.writeManagersLog(text);
|
tools.writeManagersLog(text);
|
||||||
@@ -1050,8 +1076,8 @@ const MyTelegramBot = {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
},
|
},
|
||||||
getMsgByTipoMsg: async function (mydata, lang, user, sonosognatore) {
|
getMsgByTipoMsg: async function (mydata, lang, user, sonosognatore) {
|
||||||
if (!!mydata.msgextra) {
|
if (!!mydata.msgextra) {
|
||||||
return { body: mydata.msgextra, title: '' };
|
return { body: mydata.msgextra, title: '' };
|
||||||
}
|
}
|
||||||
@@ -1119,16 +1145,16 @@ const MyTelegramBot = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return { body: msg, title };
|
return { body: msg, title };
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMsgTelegramToTheAdminAllSites: async function (text, senzaintestazione) {
|
sendMsgTelegramToTheAdminAllSites: async function (text, senzaintestazione) {
|
||||||
for (const idapp of this.getAppTelegram()) {
|
for (const idapp of this.getAppTelegram()) {
|
||||||
text = text.replace('{appname}', tools.getNomeAppByIdApp(idapp));
|
text = text.replace('{appname}', tools.getNomeAppByIdApp(idapp));
|
||||||
await this.sendMsgTelegramToTheAdmin(idapp, text, senzaintestazione);
|
await this.sendMsgTelegramToTheAdmin(idapp, text, senzaintestazione);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMsgTelegramToTheAdmin: async function (idapp, text, senzaintestazione) {
|
sendMsgTelegramToTheAdmin: async function (idapp, text, senzaintestazione) {
|
||||||
const usersmanagers = await User.getusersManagers(idapp);
|
const usersmanagers = await User.getusersManagers(idapp);
|
||||||
|
|
||||||
let intestaz = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': ';
|
let intestaz = emo.ROBOT_FACE + '[BOT-ADMIN]' + emo.ADMIN + ': ';
|
||||||
@@ -1146,9 +1172,9 @@ const MyTelegramBot = {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMsgTelegramToALL: async function (idapp, text) {
|
sendMsgTelegramToALL: async function (idapp, text) {
|
||||||
const usersall = await User.getUsersTelegALL(idapp);
|
const usersall = await User.getUsersTelegALL(idapp);
|
||||||
|
|
||||||
if (usersall) {
|
if (usersall) {
|
||||||
@@ -1158,9 +1184,9 @@ const MyTelegramBot = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMsgTelegram: async function (
|
sendMsgTelegram: async function (
|
||||||
idapp, username, text, alsotomanagers = false, username_mitt = '') {
|
idapp, username, text, alsotomanagers = false, username_mitt = '') {
|
||||||
const { User } = require('../models/user');
|
const { User } = require('../models/user');
|
||||||
|
|
||||||
@@ -1184,9 +1210,9 @@ const MyTelegramBot = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ris;
|
return ris;
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMsgTelegramByIdTelegram: async function (
|
sendMsgTelegramByIdTelegram: async function (
|
||||||
idapp, idtelegram, text, message_id, chat_id, ripr_menuPrec,
|
idapp, idtelegram, text, message_id, chat_id, ripr_menuPrec,
|
||||||
MyForm = null) {
|
MyForm = null) {
|
||||||
|
|
||||||
@@ -1203,24 +1229,24 @@ const MyTelegramBot = {
|
|||||||
chat_id, ripr_menuPrec);
|
chat_id, ripr_menuPrec);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
reloadMenuBot: async function (idapp) {
|
reloadMenuBot: async function (idapp) {
|
||||||
|
|
||||||
const cl = getclTelegByidapp(idapp);
|
const cl = getclTelegByidapp(idapp);
|
||||||
if (cl) {
|
if (cl) {
|
||||||
return cl.updateMenuBot();
|
return cl.updateMenuBot();
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
reloadSites: async function () {
|
reloadSites: async function () {
|
||||||
|
|
||||||
tools.loadApps();
|
tools.loadApps();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMsgFromSite: async function (idapp, user, params) {
|
sendMsgFromSite: async function (idapp, user, params) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let ris = {
|
let ris = {
|
||||||
@@ -1262,9 +1288,9 @@ const MyTelegramBot = {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('sendMsgFromSite', e);
|
console.error('sendMsgFromSite', e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sendMsgFromSiteToBotTelegram: async function (idapp, user, params) {
|
sendMsgFromSiteToBotTelegram: async function (idapp, user, params) {
|
||||||
|
|
||||||
if (!params.typesend) {
|
if (!params.typesend) {
|
||||||
params.typesend = shared_consts.TypeSend.TELEGRAM;
|
params.typesend = shared_consts.TypeSend.TELEGRAM;
|
||||||
@@ -1272,7 +1298,7 @@ const MyTelegramBot = {
|
|||||||
|
|
||||||
return this.sendMsgFromSite(idapp, user, params);
|
return this.sendMsgFromSite(idapp, user, params);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user