correzione numseen, numfav, ...: ora li ho aggiunti alle tabelle...

This commit is contained in:
Surya Paolo
2023-10-01 01:24:47 +02:00
parent 142dcadca9
commit b6579832b6
27 changed files with 8952 additions and 8875 deletions

View File

@@ -5,6 +5,8 @@ const tools = require('../tools/general');
const server_constants = require('../tools/server_constants');
const shared_consts = require('../tools/shared_nodejs');
const { authenticate } = require('../middleware/authenticate');
const mongoose = require('mongoose').set('debug', false);
@@ -82,7 +84,8 @@ router.post('/load', authenticate, async (req, res) => {
data.account = await Account.getAccountByUsernameAndCircuitId(idapp, '', data._id, false, false, '', data.path);
}
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp);
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
/// E' QUIIII !!!!
const useraccounts = await Account.getUserAccounts(idapp, req.user.username);
await User.setLastCircuitOpened(idapp, req.user.username, path);

View File

@@ -428,6 +428,7 @@ router.post('/settable', authenticate, async (req, res) => {
return await myPromise
.then(async (doupdate) => {
if (doupdate)
return mytable.updateOne({ _id: mytablerec._id }, mydata, { new: true })
else

View File

@@ -8,35 +8,39 @@ const tools = require('../tools/general');
var server_constants = require('../tools/server_constants');
var {authenticate, auth_default} = require('../middleware/authenticate');
var { authenticate, authenticate_noerror, auth_default } = require('../middleware/authenticate');
var mongoose = require('mongoose').set('debug', false);
const Subscription = mongoose.model('subscribers');
const _ = require('lodash');
const {MyBacheca} = require('../models/mybacheca');
var {User} = require('../models/user');
const { MyBacheca } = require('../models/mybacheca');
var { User } = require('../models/user');
const { Reaction } = require('../models/reaction');
const globalTables = require('../tools/globalTables');
const {ObjectID} = require('mongodb');
const { ObjectID } = require('mongodb');
//GET orders
router.post('/page', authenticate, function(req, res, next) {
router.post('/page', authenticate_noerror, function (req, res, next) {
const {SendNotif} = require('../models/sendnotif');
const { SendNotif } = require('../models/sendnotif');
try {
let table = req.body.table;
let id = req.body.id;
let idapp = req.body.idapp;
const username = req.user.username ? req.user.username : '';
let username = ''
if (req.user)
username = req.user.username ? req.user.username : '';
// Check if ìs a Notif to read
const idnotif = req.body.idnotif ? req.body.idnotif : '';
SendNotif.setNotifAsRead(idapp, username, idnotif);
if (username) {
// Check if ìs a Notif to read
const idnotif = req.body.idnotif ? req.body.idnotif : '';
SendNotif.setNotifAsRead(idapp, username, idnotif);
}
let mytable = null;
if (shared_consts.TABLES_ENABLE_GETREC_BYID.includes(table)) {
@@ -47,29 +51,30 @@ router.post('/page', authenticate, function(req, res, next) {
if (mytable) {
return mytable.getMyRecById(idapp, id).
then(async (ris) => {
then(async (ris) => {
// Se è un record singolo di tipo Reaction,
// allora gli devo passare anche le liste degli utenti :
/*if (globalTables.isTableReaction(table)) {
// ...
const myreaction = await Reaction.find({idapp, idrec: id}).lean();
ris.myreaction = myreaction;
};*/
// Se è un record singolo di tipo Reaction,
// allora gli devo passare anche le liste degli utenti :
if (globalTables.isTableReaction(table)) {
// ...
// const myreaction = await Reaction.find({idapp, idrec: id}).lean();
// ris.myreaction = myreaction;
if (ris) {
res.send(ris);
};
} else {
res.status(400).send();
}
}).catch((e) => {
console.error('Err', e);
res.status(400).send(e);
})
if (ris) {
res.send(ris);
} else {
res.status(400).send();
}
}).catch((e) => {
console.error('Err', e);
res.status(400).send(e);
})
}
}catch (e) {
} catch (e) {
console.error('/page', e);
}

View File

@@ -25,13 +25,14 @@ const _ = require('lodash');
const reg = require('../reg/registration');
const { authenticate } = require('../middleware/authenticate');
const { authenticate, authenticate_noerror } = require('../middleware/authenticate');
const TypedError = require('../modules/ErrorHandler');
const globalTables = require('../tools/globalTables');
const mongoose = require('mongoose').set('debug', false);
router.post('/cmd', authenticate, async (req, res) => {
router.post('/cmd', authenticate_noerror, async (req, res) => {
const mydata = req.body.mydata;
const idapp = req.body.idapp;
@@ -43,17 +44,29 @@ router.post('/cmd', authenticate, async (req, res) => {
try {
const username = req.user.username;
const table = tools.getTableByNumTab(tab);
const mytable = globalTables.getTableByTableName(table);
let username = '';
if (req.user) {
username = req.user.username;
} else {
return res.send({ state: 0, record: null });
}
let ris = null;
let record = null;
const { User } = require('../models/user');
let objtoupdate = {};
if (cmd === shared_consts.CMD_REACTION.SET_FAVORITE) {
if (tab) {
if (value)
if (value) {
ris = await Reaction.addFavorite(req, idapp, username, id, tab);
else
} else {
ris = await Reaction.removeFavorite(idapp, username, id, tab);
}
}
} else if (cmd === shared_consts.CMD_REACTION.SET_BOOKMARK) {
@@ -62,6 +75,7 @@ router.post('/cmd', authenticate, async (req, res) => {
ris = await Reaction.addBookmark(req, idapp, username, id, tab);
else
ris = await Reaction.removeBookmark(idapp, username, id, tab);
}
} else if (cmd === shared_consts.CMD_REACTION.SET_ATTEND) {
if (tab) {
@@ -69,6 +83,7 @@ router.post('/cmd', authenticate, async (req, res) => {
ris = await Reaction.addAttend(req, idapp, username, id, tab, num);
else
ris = await Reaction.removeAttend(idapp, username, id, tab);
}
} else if (cmd === shared_consts.CMD_REACTION.SET_SEEN) {
if (tab) {
@@ -83,8 +98,21 @@ router.post('/cmd', authenticate, async (req, res) => {
}
}
let state = (value && ris && ris.ok === 1) ? 1 : ((!value && ris && ris.ok === 1) ? -1 : 0);
const risreac = await Reaction.calcReactions(idapp, id, tab);
if (risreac) {
delete risreac._id;
objtoupdate = risreac;
}
if (mytable) {
ris = await mytable.updateOne({ _id: id }, {
$set: objtoupdate,
})
}
return res.send({ state, record });
} catch (e) {

View File

@@ -144,7 +144,7 @@ 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(async (arrnotif) => {
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER).then(async (arrnotif) => {
// const wait = new Promise((resolve, reject) => {
// setTimeout(() => {

View File

@@ -705,6 +705,26 @@ router.post('/circuits', authenticate, (req, res) => {
});
router.post('/updatesaldo', authenticate, async (req, res) => {
const username = req.user.username;
idapp = req.body.idapp;
locale = req.body.locale;
try {
const userprofile = await User.getExtraInfoByUsername(idapp, username);
let ris = {
userprofile
}
return res.send({ris});
} catch (e) {
tools.mylog('ERRORE IN updatesaldo: ' + e);
res.status(400).send();
};
});
router.post('/friends/cmd', authenticate, async (req, res) => {
const usernameLogged = req.user.username;
const idapp = req.body.idapp;
@@ -1166,6 +1186,10 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
console.log('e', e);
}
} else if (mydata.dbop === 'removeRecordsFav') {
// Passa le tabelle da users sulle nuove tabelle:
await User.removerecordsFavorite();
} else if (mydata.dbop === 'newRecordsFav') {
// Passa le tabelle da users sulle nuove tabelle:
await User.moverecordsFavorite(1);