fix Saldo when press refuse coins.
fix Risolvere problema del ritardo quando si fa il primo login...
This commit is contained in:
@@ -7,7 +7,7 @@ module.exports = {
|
|||||||
watch: false,
|
watch: false,
|
||||||
env: {
|
env: {
|
||||||
"PORT": 3000,
|
"PORT": 3000,
|
||||||
"NODE_ENV": "development"
|
"NODE_ENV": "development",
|
||||||
},
|
},
|
||||||
env_test: {
|
env_test: {
|
||||||
"PORT": 3001,
|
"PORT": 3001,
|
||||||
|
|||||||
@@ -54,8 +54,6 @@
|
|||||||
"ID_CIRCUIT_COINS_ACCEPTED_TO_ME": "%s %s accettati da %s.",
|
"ID_CIRCUIT_COINS_ACCEPTED_TO_ME": "%s %s accettati da %s.",
|
||||||
"ID_CIRCUIT_COINS_REFUSED": "%s %s rifiutati da %s.",
|
"ID_CIRCUIT_COINS_REFUSED": "%s %s rifiutati da %s.",
|
||||||
"ID_CIRCUIT_COINS_REFUSED_TO_ME": "%s %s rifiutati da %s.",
|
"ID_CIRCUIT_COINS_REFUSED_TO_ME": "%s %s rifiutati da %s.",
|
||||||
"CIRCUIT_AMOUNT_EXCEED_FIDO": "L'importo supera la quantità massima concessa",
|
|
||||||
"CIRCUIT_AMOUNT_EXCEED_QTAMAX": "L'importo supera la quantità massima che il destinatario può accumulare",
|
|
||||||
"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"
|
||||||
|
|||||||
@@ -57,8 +57,8 @@
|
|||||||
"ID_CIRCUIT_COINS_ACCEPTED_TO_ME": "%s %s sono stati accettati da %s.",
|
"ID_CIRCUIT_COINS_ACCEPTED_TO_ME": "%s %s sono stati accettati da %s.",
|
||||||
"ID_CIRCUIT_COINS_REFUSED": "%s %s rifiutati da %s.",
|
"ID_CIRCUIT_COINS_REFUSED": "%s %s rifiutati da %s.",
|
||||||
"ID_CIRCUIT_COINS_REFUSED_TO_ME": "%s %s rifiutati da %s.",
|
"ID_CIRCUIT_COINS_REFUSED_TO_ME": "%s %s rifiutati da %s.",
|
||||||
"CIRCUIT_AMOUNT_EXCEED_FIDO": "L'importo supera la quantità massima concessa",
|
"CIRCUIT_AMOUNT_EXCEED_FIDO": "L'importo supera la quantità massima concessa per %s",
|
||||||
"CIRCUIT_AMOUNT_EXCEED_QTAMAX": "L'importo supera la quantità massima che il destinatario può accumulare",
|
"CIRCUIT_AMOUNT_EXCEED_QTAMAX": "L'importo supera la quantità massima che il destinatario (%s) può accumulare",
|
||||||
"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"
|
||||||
|
|||||||
@@ -485,16 +485,18 @@ CircuitSchema.statics.sendCoins = async function(onlycheck, idapp, usernameOrig,
|
|||||||
// Check if Sender has enough money
|
// Check if Sender has enough money
|
||||||
if (accountorigTable.saldo - myqty < -accountorigTable.fidoConcesso) {
|
if (accountorigTable.saldo - myqty < -accountorigTable.fidoConcesso) {
|
||||||
ris.cansend = false;
|
ris.cansend = false;
|
||||||
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_FIDO');
|
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_FIDO', usernameOrig);
|
||||||
}
|
}
|
||||||
if (accountdestTable.saldo + myqty > accountorigTable.qta_maxConcessa) {
|
if (accountdestTable.saldo + myqty > accountorigTable.qta_maxConcessa) {
|
||||||
ris.cansend = false;
|
ris.cansend = false;
|
||||||
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_QTAMAX');
|
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_QTAMAX', extrarec.dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!onlycheck) {
|
if (!onlycheck) {
|
||||||
// Add a Transaction !
|
// Add a Transaction !
|
||||||
|
if (ris.cansend) {
|
||||||
ris.rec = await Movement.addMov(idapp, accountorigTable, accountdestTable, myqty, extrarec.causal);
|
ris.rec = await Movement.addMov(idapp, accountorigTable, accountdestTable, myqty, extrarec.causal);
|
||||||
|
}
|
||||||
|
|
||||||
if (ris.cansend && ris.rec) {
|
if (ris.cansend && ris.rec) {
|
||||||
|
|
||||||
|
|||||||
@@ -1375,6 +1375,9 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
|||||||
lang: 1,
|
lang: 1,
|
||||||
index: 1,
|
index: 1,
|
||||||
username: 1,
|
username: 1,
|
||||||
|
aportador_solidario: 1,
|
||||||
|
name: 1,
|
||||||
|
surname: 1,
|
||||||
deleted: 1,
|
deleted: 1,
|
||||||
sospeso: 1,
|
sospeso: 1,
|
||||||
reported: 1,
|
reported: 1,
|
||||||
@@ -1382,12 +1385,28 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
|||||||
username_who_report: 1,
|
username_who_report: 1,
|
||||||
verified_email: 1,
|
verified_email: 1,
|
||||||
verified_by_aportador: 1,
|
verified_by_aportador: 1,
|
||||||
aportador_solidario: 1,
|
'profile.nationality': 1,
|
||||||
date_reg: 1,
|
'profile.mygroups': 1,
|
||||||
|
'profile.mycircuits': 1,
|
||||||
|
'profile.qualifica': 1,
|
||||||
|
'profile.biografia': 1,
|
||||||
|
'profile.teleg_id': 1,
|
||||||
'profile.username_telegram': 1,
|
'profile.username_telegram': 1,
|
||||||
|
'profile.firstname_telegram': 1,
|
||||||
|
'profile.lastname_telegram': 1,
|
||||||
|
'profile.intcode_cell': 1,
|
||||||
|
'profile.cell': 1,
|
||||||
|
'profile.website': 1,
|
||||||
'profile.img': 1,
|
'profile.img': 1,
|
||||||
"useraport.username": 1,
|
'profile.sex': 1,
|
||||||
"useraport.profile.img": 1,
|
'profile.dateofbirth': 1,
|
||||||
|
'profile.born_city_id': 1,
|
||||||
|
'profile.born_province': 1,
|
||||||
|
'profile.born_country': 1,
|
||||||
|
email: 1,
|
||||||
|
date_reg: 1,
|
||||||
|
'useraport.username': 1,
|
||||||
|
'useraport.profile.img': 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
} else if (perm === tools.Perm.PERM_FRIEND) {
|
} else if (perm === tools.Perm.PERM_FRIEND) {
|
||||||
@@ -1425,8 +1444,8 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
|||||||
'profile.born_country': 1,
|
'profile.born_country': 1,
|
||||||
email: 1,
|
email: 1,
|
||||||
date_reg: 1,
|
date_reg: 1,
|
||||||
"useraport.username": 1,
|
'useraport.username': 1,
|
||||||
"useraport.profile.img": 1,
|
'useraport.profile.img': 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
} else if (perm === tools.Perm.PERM_ALL) {
|
} else if (perm === tools.Perm.PERM_ALL) {
|
||||||
@@ -1467,8 +1486,8 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
|||||||
'comune': 1,
|
'comune': 1,
|
||||||
email: 1,
|
email: 1,
|
||||||
date_reg: 1,
|
date_reg: 1,
|
||||||
"useraport.username": 1,
|
'useraport.username': 1,
|
||||||
"useraport.profile.img": 1,
|
'useraport.profile.img': 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1488,28 +1507,33 @@ UserSchema.statics.getUserProfileByUsername = async function(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$lookup": {
|
'$lookup': {
|
||||||
"from": 'users',
|
'from': 'users',
|
||||||
let: {
|
let: {
|
||||||
"idapp": "$idapp",
|
'idapp': '$idapp',
|
||||||
"user_name": "$aportador_solidario"
|
'user_name': '$aportador_solidario',
|
||||||
},
|
},
|
||||||
pipeline: [
|
pipeline: [
|
||||||
{ "$match": {
|
{
|
||||||
"$expr": {
|
'$match': {
|
||||||
|
'$expr': {
|
||||||
$and: [
|
$and: [
|
||||||
{ $eq: ['$username', '$$user_name'] },
|
{$eq: ['$username', '$$user_name']},
|
||||||
{ $eq: ['$idapp','$$idapp'] }
|
{$eq: ['$idapp', '$$idapp']},
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
as: 'useraport'
|
},
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
as: 'useraport',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$unwind:'$useraport'
|
$unwind:
|
||||||
|
{
|
||||||
|
path: '$useraport',
|
||||||
|
preserveNullAndEmptyArrays: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -1833,17 +1857,20 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user
|
|||||||
if (ris) {
|
if (ris) {
|
||||||
// Send a notification to the DESTINATION!
|
// Send a notification to the DESTINATION!
|
||||||
// Sei stato segnalato da %s per comportamenti non idonei. Contatta %s per chiarimenti
|
// Sei stato segnalato da %s per comportamenti non idonei. Contatta %s per chiarimenti
|
||||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false,
|
||||||
|
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||||
|
|
||||||
// Send a notification to the SENDER !
|
// Send a notification to the SENDER !
|
||||||
// Hai segnalato %s da %s per comportamenti non idonei.
|
// Hai segnalato %s da %s per comportamenti non idonei.
|
||||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: username_action, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: username_action, username_action}, false,
|
||||||
|
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||||
|
|
||||||
if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) {
|
if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) {
|
||||||
// Send a notification to the Admin
|
// Send a notification to the Admin
|
||||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
|
await SendNotif.createNewNotifToSingleUser(req, null,
|
||||||
|
{username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
|
||||||
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||||
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
shared_consts.TypeNotifs.ID_FRIENDS_REPORTED);
|
||||||
}
|
}
|
||||||
@@ -1862,7 +1889,8 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user
|
|||||||
|
|
||||||
if (ris) {
|
if (ris) {
|
||||||
// Send a notification to the DESTINATION!
|
// Send a notification to the DESTINATION!
|
||||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false, shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false,
|
||||||
|
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||||
shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED);
|
shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED);
|
||||||
|
|
||||||
// Send a notification to the SENDER !
|
// Send a notification to the SENDER !
|
||||||
@@ -1873,7 +1901,8 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user
|
|||||||
|
|
||||||
if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) {
|
if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) {
|
||||||
// Send a notification to the Admin
|
// Send a notification to the Admin
|
||||||
await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
|
await SendNotif.createNewNotifToSingleUser(req, null,
|
||||||
|
{username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false,
|
||||||
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
shared_consts.TypeNotifs.TYPEDIR_FRIENDS,
|
||||||
shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED);
|
shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED);
|
||||||
}
|
}
|
||||||
@@ -1936,7 +1965,6 @@ UserSchema.statics.countUsersInCircuit = async function(idapp, circuitname) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
|
UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) {
|
||||||
|
|
||||||
let ris = null;
|
let ris = null;
|
||||||
@@ -2212,7 +2240,8 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
|
|
||||||
if (outres.cansend) {
|
if (outres.cansend) {
|
||||||
// Invia una notifica di moneta alla persona
|
// Invia una notifica di moneta alla persona
|
||||||
outres.result = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
outres.result = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action,
|
||||||
|
extrarec);
|
||||||
} else {
|
} else {
|
||||||
outres.cansend = false;
|
outres.cansend = false;
|
||||||
}
|
}
|
||||||
@@ -2239,10 +2268,8 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna
|
|||||||
outres.cansend = true;
|
outres.cansend = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outres.cansend) {
|
// Invia una notifica di moneta (accettata o rifiutata) alla persona
|
||||||
// Invia una notifica di moneta alla persona
|
|
||||||
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, extrarec);
|
||||||
}
|
|
||||||
|
|
||||||
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
|
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
|
||||||
|
|
||||||
@@ -3772,10 +3799,14 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (recUser._doc.profile.notifs.length <= 0) {
|
try {
|
||||||
|
if (recUser._doc.profile && recUser._doc.profile.notifs && recUser._doc.profile.notifs.length <= 0) {
|
||||||
recUser._doc.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
|
recUser._doc.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
|
||||||
await recUser.save();
|
await recUser.save();
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err addExtraInfo notifs ', e);
|
||||||
|
}
|
||||||
|
|
||||||
const listSentMyRequestFriends = await User.find({
|
const listSentMyRequestFriends = await User.find({
|
||||||
idapp,
|
idapp,
|
||||||
@@ -3841,10 +3872,12 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) {
|
|||||||
|
|
||||||
recUser._doc.profile = {...recUser._doc.profile, ...circuitobj, useraccounts};
|
recUser._doc.profile = {...recUser._doc.profile, ...circuitobj, useraccounts};
|
||||||
|
|
||||||
|
recUser._doc.calcstat = await User.calculateStat(idapp, recUser.username);
|
||||||
|
|
||||||
return recUser._doc;
|
return recUser._doc;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Err', e);
|
console.error('Err addExtraInfo', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return recUser;
|
return recUser;
|
||||||
|
|||||||
@@ -218,6 +218,26 @@ router.post('/testServer', authenticate_noerror, async (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/test1', authenticate_noerror, async (req, res) => {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const test = req.query.test;
|
||||||
|
let ris = {test};
|
||||||
|
|
||||||
|
if (req.user) {
|
||||||
|
await tools.sendNotificationToUser(req.user._id, 'Test Server',
|
||||||
|
'Test Server OK',
|
||||||
|
'/', '', 'server', []);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.send(ris);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('testServer', e.message);
|
||||||
|
return res.status(400).send(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
router.post('/settable', authenticate, async (req, res) => {
|
router.post('/settable', authenticate, async (req, res) => {
|
||||||
const params = req.body;
|
const params = req.body;
|
||||||
const mytable = globalTables.getTableByTableName(params.table);
|
const mytable = globalTables.getTableByTableName(params.table);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@@ -7,6 +8,9 @@ const server_constants = require('../tools/server_constants');
|
|||||||
const {authenticate} = require('../middleware/authenticate');
|
const {authenticate} = require('../middleware/authenticate');
|
||||||
|
|
||||||
const {SendNotif} = require('../models/sendnotif');
|
const {SendNotif} = require('../models/sendnotif');
|
||||||
|
const {User} = require('../models/user');
|
||||||
|
|
||||||
|
const shared_consts = require('../tools/shared_nodejs');
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
@@ -27,20 +31,29 @@ router.post('/', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/setall/:username/:idapp', authenticate, async (req, res) => {
|
router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
||||||
|
|
||||||
const idapp = req.params.idapp;
|
const idapp = req.params.idapp;
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
|
const qualinotif = req.params.qualinotif;
|
||||||
const username_call = req.user.username;
|
const username_call = req.user.username;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (username === username_call) {
|
if (username === username_call) {
|
||||||
const arrNotifs = await SendNotif.find({idapp, dest: username, read: false}).lean();
|
let query = {idapp, dest: username, read: false};
|
||||||
|
|
||||||
|
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS) {
|
||||||
|
query.typedir = {$eq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
|
||||||
|
} else if (qualinotif === shared_consts.QualiNotifs.OTHERS) {
|
||||||
|
query.typedir = {$neq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
|
||||||
|
}
|
||||||
|
const arrNotifs = await SendNotif.find(query).lean();
|
||||||
if (arrNotifs) {
|
if (arrNotifs) {
|
||||||
for (const rec of arrNotifs) {
|
for (const rec of arrNotifs) {
|
||||||
await SendNotif.setNotifAsRead(idapp, username_call, rec._id);
|
await SendNotif.setNotifAsRead(idapp, username_call, rec._id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send(true);
|
res.send(true);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -58,6 +71,7 @@ router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (username === username_call) {
|
if (username === username_call) {
|
||||||
|
|
||||||
await SendNotif.findOneAndRemove({idapp, _id: myid});
|
await SendNotif.findOneAndRemove({idapp, _id: myid});
|
||||||
return res.send(true);
|
return res.send(true);
|
||||||
}
|
}
|
||||||
@@ -69,15 +83,23 @@ router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/delall/:username/:idapp', authenticate, async (req, res) => {
|
router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
||||||
|
|
||||||
const idapp = req.params.idapp;
|
const idapp = req.params.idapp;
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
|
const qualinotif = req.params.qualinotif;
|
||||||
const username_call = req.user.username;
|
const username_call = req.user.username;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (username === username_call) {
|
if (username === username_call) {
|
||||||
const ris = await SendNotif.deleteMany({idapp, dest: username});
|
let query = {idapp, dest: username};
|
||||||
|
|
||||||
|
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS) {
|
||||||
|
query.typedir = {$eq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
|
||||||
|
} else if (qualinotif === shared_consts.QualiNotifs.OTHERS) {
|
||||||
|
query.typedir = {$neq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
|
||||||
|
}
|
||||||
|
const ris = await SendNotif.deleteMany(query);
|
||||||
if (ris)
|
if (ris)
|
||||||
return res.send(true);
|
return res.send(true);
|
||||||
}
|
}
|
||||||
@@ -101,12 +123,14 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
|
|||||||
return res.status(404).send({code: server_constants.RIS_CODE_NOT_MY_USERNAME});
|
return res.status(404).send({code: server_constants.RIS_CODE_NOT_MY_USERNAME});
|
||||||
}
|
}
|
||||||
|
|
||||||
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp).then((arrnotif) => {
|
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp).then( async (arrnotif) => {
|
||||||
// const wait = new Promise((resolve, reject) => {
|
// const wait = new Promise((resolve, reject) => {
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
return res.send({arrnotif});
|
|
||||||
// }, 2000);
|
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||||
// });
|
const user = await User.getExtraInfoByUsername(idapp, req.user.username);
|
||||||
|
|
||||||
|
return res.send({arrnotif, user } );
|
||||||
|
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log(e.message);
|
console.log(e.message);
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ router.post('/', authenticate, async (req, res) => {
|
|||||||
if (req.body.options !== null) {
|
if (req.body.options !== null) {
|
||||||
tools.sendBackNotif(subscription, req.body.options);
|
tools.sendBackNotif(subscription, req.body.options);
|
||||||
}
|
}
|
||||||
|
console.log('Subscription saved... ')
|
||||||
return res.send({data: 'Subscription saved.'});
|
return res.send({data: 'Subscription saved.'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -387,11 +387,12 @@ router.post('/profile', authenticate, (req, res) => {
|
|||||||
|
|
||||||
//++Todo: controlla che tipo di dati ha il permesso di leggere
|
//++Todo: controlla che tipo di dati ha il permesso di leggere
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
// Check if ìs a Notif to read
|
// Check if ìs a Notif to read
|
||||||
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
|
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
|
||||||
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
|
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
|
||||||
|
|
||||||
try {
|
|
||||||
return User.getUserProfileByUsername(idapp, username, req.user.username,
|
return User.getUserProfileByUsername(idapp, username, req.user.username,
|
||||||
false, req.user.perm).
|
false, req.user.perm).
|
||||||
then((ris) => {
|
then((ris) => {
|
||||||
@@ -444,7 +445,7 @@ router.post('/panel', authenticate, async (req, res) => {
|
|||||||
if (!!myuser) {
|
if (!!myuser) {
|
||||||
res.send(myuser);
|
res.send(myuser);
|
||||||
} else {
|
} else {
|
||||||
tools.mylog('ERRORE IN panel: ' + e.message);
|
tools.mylog('ERRORE IN panel: ');
|
||||||
res.status(400).send();
|
res.status(400).send();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -455,7 +456,7 @@ router.post('/panel', authenticate, async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.post('/notifs', authenticate, async (req, res) => {
|
router.post('/notifs', authenticate, async (req, res) => {
|
||||||
const notifs = req.body['notifs'];
|
/* const notifs = req.body['notifs'];
|
||||||
idapp = req.body.idapp;
|
idapp = req.body.idapp;
|
||||||
locale = req.body.locale;
|
locale = req.body.locale;
|
||||||
|
|
||||||
@@ -479,6 +480,8 @@ router.post('/notifs', authenticate, async (req, res) => {
|
|||||||
res.status(400).send();
|
res.status(400).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/login', (req, res) => {
|
router.post('/login', (req, res) => {
|
||||||
@@ -559,7 +562,7 @@ router.post('/login', (req, res) => {
|
|||||||
// console.log('res', myris.token, myris.usertosend);
|
// console.log('res', myris.token, myris.usertosend);
|
||||||
|
|
||||||
// SEND TOKEN AND CODE RESULT
|
// SEND TOKEN AND CODE RESULT
|
||||||
res.header('x-auth', myris.token).send({
|
return res.header('x-auth', myris.token).send({
|
||||||
usertosend: myris.usertosend,
|
usertosend: myris.usertosend,
|
||||||
code: server_constants.RIS_CODE_OK,
|
code: server_constants.RIS_CODE_OK,
|
||||||
subsExistonDb: myris.subsExistonDb,
|
subsExistonDb: myris.subsExistonDb,
|
||||||
|
|||||||
@@ -48,7 +48,18 @@ if ((process.env.NODE_ENV === 'production') ||
|
|||||||
};
|
};
|
||||||
var https = require('https');
|
var https = require('https');
|
||||||
} else {
|
} else {
|
||||||
|
if (process.env.HTTPS_LOCALHOST) {
|
||||||
|
var privateKey = fs.readFileSync(process.env.PATH_CERT_KEY, 'utf8');
|
||||||
|
var certificate = fs.readFileSync(process.env.PATH_SERVER_CRT, 'utf8');
|
||||||
|
var credentials = {
|
||||||
|
key: privateKey,
|
||||||
|
cert: certificate,
|
||||||
|
};
|
||||||
|
var https = require('https');
|
||||||
|
|
||||||
|
} else {
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('DB: ' + process.env.DATABASE);
|
console.log('DB: ' + process.env.DATABASE);
|
||||||
@@ -220,7 +231,7 @@ myLoad().then(ris => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((process.env.NODE_ENV === 'production') ||
|
if ((process.env.NODE_ENV === 'production') ||
|
||||||
(process.env.NODE_ENV === 'test')) {
|
(process.env.NODE_ENV === 'test') || process.env.HTTPS_LOCALHOST) {
|
||||||
var httpsServer = https.createServer(credentials, app);
|
var httpsServer = https.createServer(credentials, app);
|
||||||
console.log('httpsServer: port ', port);
|
console.log('httpsServer: port ', port);
|
||||||
httpsServer.listen(port);
|
httpsServer.listen(port);
|
||||||
|
|||||||
@@ -361,6 +361,11 @@ module.exports = {
|
|||||||
STATUS_COINS_REFUSED_SENT: 63,
|
STATUS_COINS_REFUSED_SENT: 63,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
QualiNotifs: {
|
||||||
|
CIRCUITS: 1,
|
||||||
|
OTHERS: 2,
|
||||||
|
},
|
||||||
|
|
||||||
TypeNotifs: {
|
TypeNotifs: {
|
||||||
TYPEDIR_BACHECA: 1,
|
TYPEDIR_BACHECA: 1,
|
||||||
ID_BACHECA_NEW_GOOD: 1,
|
ID_BACHECA_NEW_GOOD: 1,
|
||||||
@@ -410,6 +415,9 @@ module.exports = {
|
|||||||
|
|
||||||
TYPEDIR_MSGS: 7,
|
TYPEDIR_MSGS: 7,
|
||||||
ID_MSGS_NEW_REC: 1,
|
ID_MSGS_NEW_REC: 1,
|
||||||
|
|
||||||
|
TYPEDIR_TEST: 444,
|
||||||
|
ID_TEST_NEW_REC: 1,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user