Pannello Utente
Aggiornamento Yarn - Notifiche (1)
This commit is contained in:
@@ -55,6 +55,7 @@ const {CalZoom} = require('../models/calzoom');
|
||||
const {Gallery} = require('../models/gallery');
|
||||
const {Settings} = require('../models/settings');
|
||||
const {SendMsg} = require('../models/sendmsg');
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const {Permission} = require('../models/permission');
|
||||
const Producer = require('../models/producer');
|
||||
const Cart = require('../models/cart');
|
||||
@@ -138,7 +139,6 @@ router.post(process.env.LINK_REQUEST_NEWPASSWORD, async (req, res) => {
|
||||
'POST ' + process.env.LINK_REQUEST_NEWPASSWORD + ' idapp= ' + idapp +
|
||||
' email = ' + email);
|
||||
|
||||
|
||||
try {
|
||||
const ris = await User.createNewRequestPwd(idapp, email);
|
||||
if (ris) {
|
||||
@@ -148,7 +148,7 @@ router.post(process.env.LINK_REQUEST_NEWPASSWORD, async (req, res) => {
|
||||
return res.status(200).
|
||||
send({code: server_constants.RIS_CODE_EMAIL_NOT_EXIST, msg: ''});
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log(process.env.LINK_REQUEST_NEWPASSWORD, e.message);
|
||||
res.status(400).send();
|
||||
res.send({code: server_constants.RIS_CODE_ERR, msg: e});
|
||||
@@ -304,11 +304,11 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
// Controlla se esiste già con lo stesso nome
|
||||
let alreadyexist = await MyGroup.findOne({idapp, groupname: mydata.groupname});
|
||||
if (alreadyexist) {
|
||||
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_CODE });
|
||||
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_CODE});
|
||||
}
|
||||
alreadyexist = await MyGroup.findOne({idapp, title: mydata.title});
|
||||
if (alreadyexist) {
|
||||
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_NAME });
|
||||
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_NAME});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,6 +444,57 @@ router.post('/gettable', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/getexp', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
let idapp = req.user.idapp;
|
||||
const myUser = globalTables.getTableByTableName('users');
|
||||
// console.log('mytable', mytable);
|
||||
if (!myUser || params.filtersearch2 !== 'fdsgas1') {
|
||||
return res.status(400).send({});
|
||||
}
|
||||
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isTutor(req.user.perm))) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (params.table === 'exp') {
|
||||
return myUser.find({
|
||||
idapp,
|
||||
$or: [
|
||||
{deleted: {$exists: false}},
|
||||
{deleted: {$exists: true, $eq: false}}],
|
||||
},
|
||||
{
|
||||
username: 1,
|
||||
email: 1,
|
||||
'profile.teleg_id': 1,
|
||||
'verified_by_aportador': 1,
|
||||
'profile.username_telegram': 1,
|
||||
'profile.firstname_telegram': 1,
|
||||
'profile.lastname_telegram': 1,
|
||||
}).then(ris => {
|
||||
|
||||
return res.send({data: ris});
|
||||
|
||||
}).catch((e) => {
|
||||
console.error('getexp: ' + e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error(`ERROR getexp ${params.table}: `, e.message, 'params',
|
||||
params);
|
||||
res.status(500).send(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.post('/pickup', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
let idapp = req.user.idapp;
|
||||
@@ -1249,8 +1300,8 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
|
||||
// const sall = '0';
|
||||
|
||||
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
|
||||
let last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId,
|
||||
req.user.username, idapp);
|
||||
let last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
|
||||
let last_notifs = SendNotif.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
|
||||
|
||||
let usersList = null;
|
||||
|
||||
@@ -1265,12 +1316,13 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all([usersList, last_msgs]).then((arrdata) => {
|
||||
return Promise.all([usersList, last_msgs, last_notifs]).then((arrdata) => {
|
||||
// console.table(arrdata);
|
||||
return res.send({
|
||||
CfgServer: arrcfgrec,
|
||||
usersList: arrdata[0],
|
||||
last_msgs: arrdata[1],
|
||||
last_notifs: arrdata[2],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1413,43 +1465,41 @@ function uploadFile(req, res, version) {
|
||||
// SMALL
|
||||
|
||||
// questa opzione 'failOnError' serve per risolvere l'errore (Error: VipsJpeg: Invalid SOS parameters for sequential JPEG
|
||||
sharp(newname, { failOnError: false }).
|
||||
sharp(newname, {failOnError: false}).
|
||||
resize(64, 64).
|
||||
withMetadata().
|
||||
toFile(resized_img_small);
|
||||
|
||||
// MEDIUM
|
||||
let resized_img = tools.extractFilePath(newname) + '/' + server_constants.PREFIX_IMG + tools.extractFileName(newname);
|
||||
sharp(newname, { failOnError: false }).
|
||||
resize( {
|
||||
sharp(newname, {failOnError: false}).
|
||||
resize({
|
||||
width: 512,
|
||||
height: 512,
|
||||
fit: sharp.fit.cover,
|
||||
position: sharp.strategy.entropy
|
||||
})
|
||||
.withMetadata()
|
||||
.toFile(resized_img, function(err) {
|
||||
position: sharp.strategy.entropy,
|
||||
}).withMetadata().toFile(resized_img, function(err) {
|
||||
|
||||
// console.log('3) Ridimensionata Immagine ' + newname, 'in', resized_img);
|
||||
// console.log('3) Ridimensionata Immagine ' + newname, 'in', resized_img);
|
||||
|
||||
if (tools.isFileExists(resized_img)) {
|
||||
// console.log('4) Cancella l \'immagine grande originale:', newname);
|
||||
// DELETE THE ORIGINAL BIG
|
||||
tools.delete(newname, false, () => {});
|
||||
|
||||
// console.log('5) Rinomina l\'immagine Media da', resized_img, 'a:', newname);
|
||||
// RENAME THE MEDIUM IN THE ORIGINAL NAME
|
||||
tools.move(resized_img, newname, (err) => {
|
||||
if (err)
|
||||
console.error('err', err);
|
||||
else
|
||||
console.log('move', newname);
|
||||
});
|
||||
}
|
||||
if (tools.isFileExists(resized_img)) {
|
||||
// console.log('4) Cancella l \'immagine grande originale:', newname);
|
||||
// DELETE THE ORIGINAL BIG
|
||||
tools.delete(newname, false, () => {});
|
||||
|
||||
// console.log('5) Rinomina l\'immagine Media da', resized_img, 'a:', newname);
|
||||
// RENAME THE MEDIUM IN THE ORIGINAL NAME
|
||||
tools.move(resized_img, newname, (err) => {
|
||||
if (err)
|
||||
console.error('Error Upload: ', err);
|
||||
console.error('err', err);
|
||||
else
|
||||
console.log('move', newname);
|
||||
});
|
||||
}
|
||||
|
||||
if (err)
|
||||
console.error('Error Upload: ', err);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Error Upload(2) ', e);
|
||||
}
|
||||
|
||||
113
src/server/router/sendnotif_router.js
Executable file
113
src/server/router/sendnotif_router.js
Executable file
@@ -0,0 +1,113 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const tools = require('../tools/general');
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const { User } = require('../models/user');
|
||||
const { Operator } = require('../models/operator');
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
|
||||
async function sendNotif(res, idapp, user, recnotif) {
|
||||
// Controlla nelle impostazioni che tipo di Notifica visualizzare
|
||||
|
||||
|
||||
if (tools.isBitActive(recnotif.options, shared_consts.MessageOptions.Notify_ByPushNotification)) {
|
||||
if (this.checkifSendPushNotification) {
|
||||
console.log('SEND PUSH NOTIFICATION ')
|
||||
//++Todo: tools.sendNotificationToUser
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Read from the operator table first
|
||||
let emaildest = await Operator.getEmailByUsername(recnotif.dest.idapp, recnotif.dest.username);
|
||||
if (!emaildest)
|
||||
emaildest = await User.getEmailByUsername(recnotif.dest.idapp, recnotif.dest.username);
|
||||
|
||||
console.log('emaildest', emaildest);
|
||||
|
||||
// Send Msg by EMAIL
|
||||
if (emaildest && tools.isBitActive(recnotif.options, shared_consts.MessageOptions.Notify_ByEmail))
|
||||
await sendemail.sendEmail_Msg(res, user.lang, emaildest, user, idapp, recnotif);
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
tools.mylog('INIZIO - SendNotif');
|
||||
// tools.mylog('req.body', req.body);
|
||||
const body = _.pick(req.body, tools.allfieldSendNotif());
|
||||
|
||||
tools.mylog('crea SendNotif');
|
||||
const myrecnotif = new SendNotif(body);
|
||||
|
||||
const check = tools.checkUserOk(myrecnotif.sender, req.user.username, res);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
// console.log('fieldtochange', fieldtochange);
|
||||
|
||||
myrecnotif._id = new ObjectID();
|
||||
return myrecnotif.save()
|
||||
.then((writeresult) => {
|
||||
let idobj = writeresult._id;
|
||||
|
||||
myrecnotif._id = idobj;
|
||||
|
||||
return SendNotif.findById(idobj)
|
||||
.then(async (recnotif) => {
|
||||
// Add this field because I don't want to add into the database
|
||||
|
||||
return await sendNotif(res, body.idapp, req.user, recnotif).then((ris) => {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, notif: '', id: recnotif._id });
|
||||
})
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
// res.status(400).send(e);
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, notif: '' });
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
|
||||
// Extract all the todos of the userId only
|
||||
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp).then((arrnotif) => {
|
||||
// const wait = new Promise((resolve, reject) => {
|
||||
// setTimeout(() => {
|
||||
res.send({ arrnotif });
|
||||
// }, 2000);
|
||||
// });
|
||||
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
@@ -403,6 +403,36 @@ router.post('/profile', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/panel', authenticate, async (req, res) => {
|
||||
const username = req.body['username'];
|
||||
idapp = req.body.idapp;
|
||||
locale = req.body.locale;
|
||||
|
||||
if (!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
||||
}
|
||||
|
||||
try {
|
||||
const myuser = await User.findOne({idapp, username},
|
||||
{username: 1, email: 1, verified_by_aportador: 1, aportador_solidario: 1,
|
||||
lasttimeonline: 1,
|
||||
deleted: 1,
|
||||
profile: 1}).lean();
|
||||
if (!!myuser) {
|
||||
res.send(myuser);
|
||||
} else {
|
||||
tools.mylog('ERRORE IN panel: ' + e.message);
|
||||
res.status(400).send();
|
||||
}
|
||||
} catch (e) {
|
||||
tools.mylogserr('Error profile: ', e);
|
||||
res.status(400).send();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.post('/login', (req, res) => {
|
||||
var body = _.pick(req.body,
|
||||
['username', 'password', 'idapp', 'keyappid', 'lang']);
|
||||
|
||||
Reference in New Issue
Block a user