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

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