fix Saldo when press refuse coins.

fix Risolvere problema del ritardo quando si fa il primo login...
This commit is contained in:
Paolo Arena
2022-09-16 17:38:49 +02:00
parent 9f34a6b916
commit 671a39e51c
11 changed files with 162 additions and 62 deletions

View File

@@ -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);