2022-02-16 19:21:12 +01:00
|
|
|
const shared_consts = require('../tools/shared_nodejs');
|
|
|
|
|
|
|
|
|
|
const express = require('express');
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
|
2023-09-27 18:38:57 +02:00
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
var server_constants = require('../tools/server_constants');
|
|
|
|
|
|
|
|
|
|
var {authenticate, auth_default} = require('../middleware/authenticate');
|
|
|
|
|
|
2022-09-14 11:32:04 +02:00
|
|
|
var mongoose = require('mongoose').set('debug', false);
|
2022-02-16 19:21:12 +01:00
|
|
|
const Subscription = mongoose.model('subscribers');
|
|
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
const {MyBacheca} = require('../models/mybacheca');
|
|
|
|
|
var {User} = require('../models/user');
|
2023-09-27 18:38:57 +02:00
|
|
|
const { Reaction } = require('../models/reaction');
|
2022-02-16 19:21:12 +01:00
|
|
|
|
|
|
|
|
const globalTables = require('../tools/globalTables');
|
|
|
|
|
|
|
|
|
|
const {ObjectID} = require('mongodb');
|
|
|
|
|
|
|
|
|
|
//GET orders
|
|
|
|
|
router.post('/page', authenticate, function(req, res, next) {
|
|
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
const {SendNotif} = require('../models/sendnotif');
|
2022-02-16 19:21:12 +01:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let table = req.body.table;
|
|
|
|
|
let id = req.body.id;
|
|
|
|
|
let idapp = req.body.idapp;
|
|
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
const 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);
|
|
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
let mytable = null;
|
|
|
|
|
if (shared_consts.TABLES_ENABLE_GETREC_BYID.includes(table)) {
|
|
|
|
|
mytable = globalTables.getTableByTableName(table);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 18:38:57 +02:00
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
if (mytable) {
|
|
|
|
|
|
|
|
|
|
return mytable.getMyRecById(idapp, id).
|
2023-09-27 18:38:57 +02:00
|
|
|
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;
|
|
|
|
|
};*/
|
2022-02-16 19:21:12 +01:00
|
|
|
|
|
|
|
|
if (ris) {
|
|
|
|
|
res.send(ris);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
}
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
console.error('Err', e);
|
|
|
|
|
res.status(400).send(e);
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}catch (e) {
|
|
|
|
|
console.error('/page', e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|