fix Saldo when press refuse coins.
fix Risolvere problema del ritardo quando si fa il primo login...
This commit is contained in:
@@ -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) => {
|
||||
const params = req.body;
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
@@ -7,6 +8,9 @@ const server_constants = require('../tools/server_constants');
|
||||
const {authenticate} = require('../middleware/authenticate');
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const {User} = require('../models/user');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
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 username = req.params.username;
|
||||
const qualinotif = req.params.qualinotif;
|
||||
const username_call = req.user.username;
|
||||
|
||||
try {
|
||||
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) {
|
||||
for (const rec of arrNotifs) {
|
||||
await SendNotif.setNotifAsRead(idapp, username_call, rec._id);
|
||||
}
|
||||
}
|
||||
|
||||
res.send(true);
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -58,6 +71,7 @@ router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
try {
|
||||
if (username === username_call) {
|
||||
|
||||
await SendNotif.findOneAndRemove({idapp, _id: myid});
|
||||
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 username = req.params.username;
|
||||
const qualinotif = req.params.qualinotif;
|
||||
const username_call = req.user.username;
|
||||
|
||||
try {
|
||||
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)
|
||||
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 SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp).then((arrnotif) => {
|
||||
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp).then( async (arrnotif) => {
|
||||
// const wait = new Promise((resolve, reject) => {
|
||||
// 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) => {
|
||||
console.log(e.message);
|
||||
|
||||
@@ -76,6 +76,7 @@ router.post('/', authenticate, async (req, res) => {
|
||||
if (req.body.options !== null) {
|
||||
tools.sendBackNotif(subscription, req.body.options);
|
||||
}
|
||||
console.log('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
|
||||
|
||||
// Check if ìs a Notif to read
|
||||
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
|
||||
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
|
||||
|
||||
try {
|
||||
// Check if ìs a Notif to read
|
||||
const idnotif = req.body['idnotif'] ? req.body['idnotif'] : '';
|
||||
SendNotif.setNotifAsRead(idapp, usernameOrig, idnotif);
|
||||
|
||||
return User.getUserProfileByUsername(idapp, username, req.user.username,
|
||||
false, req.user.perm).
|
||||
then((ris) => {
|
||||
@@ -444,7 +445,7 @@ router.post('/panel', authenticate, async (req, res) => {
|
||||
if (!!myuser) {
|
||||
res.send(myuser);
|
||||
} else {
|
||||
tools.mylog('ERRORE IN panel: ' + e.message);
|
||||
tools.mylog('ERRORE IN panel: ');
|
||||
res.status(400).send();
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -455,7 +456,7 @@ router.post('/panel', 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;
|
||||
locale = req.body.locale;
|
||||
|
||||
@@ -479,6 +480,8 @@ router.post('/notifs', authenticate, async (req, res) => {
|
||||
res.status(400).send();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
});
|
||||
|
||||
router.post('/login', (req, res) => {
|
||||
@@ -559,7 +562,7 @@ router.post('/login', (req, res) => {
|
||||
// console.log('res', myris.token, myris.usertosend);
|
||||
|
||||
// SEND TOKEN AND CODE RESULT
|
||||
res.header('x-auth', myris.token).send({
|
||||
return res.header('x-auth', myris.token).send({
|
||||
usertosend: myris.usertosend,
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
subsExistonDb: myris.subsExistonDb,
|
||||
|
||||
Reference in New Issue
Block a user