- fix RIS in pendenti, se troppi msg, non compariva piu
- cataloghi, ricerca pickup
This commit is contained in:
@@ -461,7 +461,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
name: arrrecauthor[i].trim()
|
||||
}
|
||||
if (arrrecauthor.length > i + 1) {
|
||||
surname = arrrecauthor[i + 1].trim()
|
||||
author.surname = arrrecauthor[i + 1].trim()
|
||||
}
|
||||
arrAuthor.push(author);
|
||||
} catch (e) {
|
||||
@@ -513,18 +513,22 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
}
|
||||
}
|
||||
if (productInfo.publisher) {
|
||||
publisher = productInfo.publisher.trim();
|
||||
// Cerca la Sotto Categoria
|
||||
let recpublisher = await Publisher.findOne({ idapp, name: publisher }).lean();
|
||||
if (!recpublisher) {
|
||||
// Non esiste questo Editore, quindi la creo !
|
||||
recpublisher = new Publisher({ idapp, name: publisher });
|
||||
ris = await recpublisher.save();
|
||||
recpublisher = await Publisher.findOne({ idapp, name: publisher }).lean();
|
||||
}
|
||||
try {
|
||||
publisher = productInfo.publisher.trim();
|
||||
// Cerca la Sotto Categoria
|
||||
let recpublisher = await Publisher.findOne({ idapp, name: publisher }).lean();
|
||||
if (!recpublisher) {
|
||||
// Non esiste questo Editore, quindi la creo !
|
||||
recpublisher = new Publisher({ idapp, name: publisher });
|
||||
ris = await recpublisher.save();
|
||||
recpublisher = await Publisher.findOne({ idapp, name: publisher }).lean();
|
||||
}
|
||||
|
||||
if (recpublisher) {
|
||||
productInfo.idPublisher.push(recpublisher._id);
|
||||
if (recpublisher) {
|
||||
productInfo.idPublisher = recpublisher._id;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,13 +84,14 @@ 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, shared_consts.LIMIT_NOTIF_FOR_USER);
|
||||
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_OTHERS);
|
||||
const arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_CIRCUITS);
|
||||
/// E' QUIIII !!!!
|
||||
const useraccounts = await Account.getUserAccounts(idapp, req.user.username);
|
||||
|
||||
await User.setLastCircuitOpened(idapp, req.user.username, path);
|
||||
|
||||
res.send({ circuit: data, users_in_circuit, arrrecnotif, useraccounts });
|
||||
res.send({ circuit: data, users_in_circuit, arrrecnotif, arrrecnotifcoins, useraccounts });
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error in Circuits', e);
|
||||
|
||||
@@ -73,6 +73,7 @@ const CatAI = require('../models/catai');
|
||||
const SubCatProd = require('../models/subcatprod');
|
||||
const Gasordine = require('../models/gasordine');
|
||||
const Product = require('../models/product');
|
||||
const Author = require('../models/author');
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
const Scontistica = require('../models/scontistica');
|
||||
const Department = require('../models/department');
|
||||
@@ -1488,6 +1489,7 @@ function load(req, res, version) {
|
||||
} catch (e) {
|
||||
}
|
||||
let products = Product.findAllIdApp(idapp, undefined, undefined, ismanager);
|
||||
let authors = Author.findAllIdApp(idapp);
|
||||
let productInfos = ProductInfo.findAllIdApp(idapp);
|
||||
let scontisticas = Scontistica.findAllIdApp(idapp);
|
||||
let departments = Department.findAllIdApp(idapp);
|
||||
@@ -1584,6 +1586,7 @@ function load(req, res, version) {
|
||||
subcatprods,
|
||||
catprods_gas,
|
||||
catAI,
|
||||
authors,
|
||||
]).then((arrdata) => {
|
||||
// console.table(arrdata);
|
||||
let myuser = req.user;
|
||||
@@ -1676,6 +1679,7 @@ function load(req, res, version) {
|
||||
catprods_gas: arrdata[47],
|
||||
catAI: arrdata[48],
|
||||
code: req.code,
|
||||
authors: arrdata[49],
|
||||
});
|
||||
|
||||
const prova = 1;
|
||||
@@ -1696,7 +1700,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
|
||||
return res.status(200).send();
|
||||
}
|
||||
|
||||
await CfgServer.find({ idapp }).then((arrcfgrec) => {
|
||||
await CfgServer.find({ idapp }).then(async (arrcfgrec) => {
|
||||
|
||||
if (!arrcfgrec)
|
||||
return res.status(404).send();
|
||||
@@ -1705,6 +1709,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
|
||||
|
||||
let last_msgs = null;
|
||||
let last_notifs = null;
|
||||
let last_notifcoins = null;
|
||||
let usersList = null;
|
||||
// const sall = '0';
|
||||
|
||||
@@ -1718,6 +1723,8 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
|
||||
|
||||
last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
|
||||
last_notifs = SendNotif.findLastNotifsByUserIdAndIdApp(req.user.username, idapp, 40);
|
||||
last_notifcoins_inattesa = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 200, true);
|
||||
last_notifcoins = SendNotif.findLastNotifCoinsByUserIdAndIdApp(req.user.username, idapp, 1, false);
|
||||
|
||||
if (req.user) {
|
||||
// If User is Admin, then send user Lists
|
||||
@@ -1731,13 +1738,14 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all([usersList, last_msgs, last_notifs]).then((arrdata) => {
|
||||
return Promise.all([usersList, last_msgs, last_notifs, last_notifcoins, last_notifcoins_inattesa]).then((arrdata) => {
|
||||
// console.table(arrdata);
|
||||
return res.send({
|
||||
CfgServer: arrcfgrec,
|
||||
usersList: arrdata[0],
|
||||
last_msgs: arrdata[1],
|
||||
last_notifs: arrdata[2],
|
||||
last_notifcoins: [...arrdata[4], ...arrdata[3]],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ const router = express.Router();
|
||||
const tools = require('../tools/general');
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const {authenticate} = require('../middleware/authenticate');
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const {User} = require('../models/user');
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
@@ -23,9 +23,9 @@ router.post('/', authenticate, async (req, res) => {
|
||||
|
||||
const recout = await SendNotif.saveAndSendNotif(myrecnotif, req, res);
|
||||
if (recout) {
|
||||
return res.send({code: server_constants.RIS_CODE_OK, notif: '', record: recout});
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, notif: '', record: recout });
|
||||
} else {
|
||||
return res.send({code: server_constants.RIS_CODE_ERR, notif: ''});
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, notif: '' });
|
||||
}
|
||||
|
||||
});
|
||||
@@ -39,12 +39,12 @@ router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res
|
||||
|
||||
try {
|
||||
if (username === username_call) {
|
||||
let query = {idapp, dest: username, read: false};
|
||||
let query = { idapp, dest: username, read: false };
|
||||
|
||||
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS) {
|
||||
query.typedir = {$eq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
|
||||
query.typedir = { $eq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
|
||||
} else if (qualinotif === shared_consts.QualiNotifs.OTHERS) {
|
||||
query.typedir = {$neq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
|
||||
query.typedir = { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
|
||||
}
|
||||
const arrNotifs = await SendNotif.find(query).lean();
|
||||
if (arrNotifs) {
|
||||
@@ -67,7 +67,7 @@ router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
|
||||
const username_call = req.user.username;
|
||||
|
||||
try {
|
||||
let query = {_id, dest: username_call, read: false};
|
||||
let query = { _id, dest: username_call, read: false };
|
||||
|
||||
const rec = await SendNotif.findOne(query);
|
||||
if (rec) {
|
||||
@@ -83,17 +83,13 @@ router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const idapp = req.params.idapp;
|
||||
const username = req.params.username;
|
||||
const myid = req.params.id;
|
||||
const username_call = req.user.username;
|
||||
async function delNotif(idapp, username, id, username_call) {
|
||||
|
||||
try {
|
||||
if (username === username_call) {
|
||||
|
||||
await SendNotif.findOneAndRemove({idapp, _id: myid});
|
||||
await SendNotif.findOneAndRemove({ idapp, _id: id });
|
||||
return res.send(true);
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -102,8 +98,19 @@ router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
return res.send(false);
|
||||
|
||||
};
|
||||
|
||||
router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
try {
|
||||
return delNotif(req.params.idapp, req.params.username, req.params.id, req.user.username);
|
||||
|
||||
} catch (e) {
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
||||
|
||||
const idapp = req.params.idapp;
|
||||
@@ -113,12 +120,12 @@ router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res
|
||||
|
||||
try {
|
||||
if (username === username_call) {
|
||||
let query = {idapp, dest: username};
|
||||
let query = { idapp, dest: username };
|
||||
|
||||
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS) {
|
||||
query.typedir = {$eq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
|
||||
query.typedir = { $eq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
|
||||
} else if (qualinotif === shared_consts.QualiNotifs.OTHERS) {
|
||||
query.typedir = {$neq: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS};
|
||||
query.typedir = { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
|
||||
}
|
||||
const ris = await SendNotif.deleteMany(query);
|
||||
if (ris)
|
||||
@@ -133,31 +140,45 @@ router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res
|
||||
});
|
||||
|
||||
router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
|
||||
// tools.mylog('GET NotifS : ', req.params);
|
||||
const username = req.params.username;
|
||||
const lastdataread = req.params.lastdataread;
|
||||
const idapp = req.params.idapp;
|
||||
// var category = req.params.category;
|
||||
|
||||
if (req.user.idapp !== idapp) {
|
||||
// I'm trying to get something not mine!
|
||||
return res.status(404).send({code: server_constants.RIS_CODE_NOT_MY_USERNAME});
|
||||
}
|
||||
|
||||
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER).then(async (arrnotif) => {
|
||||
// const wait = new Promise((resolve, reject) => {
|
||||
// setTimeout(() => {
|
||||
|
||||
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||
const userprofile = await User.getExtraInfoByUsername(idapp, req.user.username);
|
||||
|
||||
return res.send({arrnotif, userprofile});
|
||||
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
|
||||
return getNotif(req, res);
|
||||
});
|
||||
|
||||
router.get('/:username/:lastdataread/:idapp/:qualinotif', authenticate, (req, res) => {
|
||||
return getNotif(req, res);
|
||||
});
|
||||
|
||||
function getNotif(req, res) {
|
||||
|
||||
try {
|
||||
// tools.mylog('GET NotifS : ', req.params);
|
||||
const username = req.params.username;
|
||||
const lastdataread = req.params.lastdataread;
|
||||
const idapp = req.params.idapp;
|
||||
const qualinotif = req.params.qualinotif;
|
||||
|
||||
// var category = req.params.category;
|
||||
|
||||
if (req.user.idapp !== idapp) {
|
||||
// I'm trying to get something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_NOT_MY_USERNAME });
|
||||
}
|
||||
|
||||
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, qualinotif).then(async (arrnotif) => {
|
||||
// const wait = new Promise((resolve, reject) => {
|
||||
// setTimeout(() => {
|
||||
|
||||
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||
const userprofile = await User.getExtraInfoByUsername(idapp, req.user.username);
|
||||
|
||||
return res.send({ arrnotif, userprofile });
|
||||
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -902,9 +902,8 @@ router.post('/updatesaldo', authenticate, async (req, res) => {
|
||||
userprofile
|
||||
}
|
||||
|
||||
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
|
||||
|
||||
ris.arrrecnotif = arrrecnotif;
|
||||
ris.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_OTHERS);
|
||||
ris.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_CIRCUITS);
|
||||
|
||||
return res.send({ ris });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user