2019-02-05 03:40:22 +01:00
|
|
|
|
const express = require('express');
|
2019-12-07 00:20:06 +01:00
|
|
|
|
const router = express.Router(),
|
2021-11-22 18:29:22 +01:00
|
|
|
|
fs = require('fs'),
|
|
|
|
|
|
path = require('path');
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2020-01-30 01:19:25 +01:00
|
|
|
|
const telegrambot = require('../telegram/telegrambot');
|
|
|
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const sharp = require('sharp');
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {authenticate, authenticate_noerror} = require(
|
|
|
|
|
|
'../middleware/authenticate');
|
2019-02-22 10:23:39 +01:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {ObjectID} = require('mongodb');
|
2022-02-03 00:33:15 +01:00
|
|
|
|
// const {ListaIngresso} = require('../models/listaingresso');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {Graduatoria} = require('../models/graduatoria');
|
2019-02-22 10:23:39 +01:00
|
|
|
|
|
2022-09-14 11:32:04 +02:00
|
|
|
|
const mongoose = require('mongoose').set('debug', false);
|
2022-05-14 00:31:53 +02:00
|
|
|
|
const {CfgServer} = require('../models/cfgserver');
|
2019-02-22 10:23:39 +01:00
|
|
|
|
|
2022-03-09 14:53:09 +01:00
|
|
|
|
// const uuidv4 = require('uuid/v4'); // I chose v4 ‒ you can select others
|
2022-01-23 23:25:34 +01:00
|
|
|
|
|
2022-03-09 14:53:09 +01:00
|
|
|
|
// const ftp = require('../ftp/FTPClient');
|
|
|
|
|
|
const formidable = require('formidable');
|
|
|
|
|
|
const folder = path.join(__dirname, 'upload');
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(folder)) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
fs.mkdirSync(folder);
|
2019-12-07 00:20:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-06 18:48:32 +01:00
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {User} = require('../models/user');
|
2022-02-03 00:33:15 +01:00
|
|
|
|
const {MyGroup} = require('../models/mygroup');
|
2022-09-03 13:06:58 +02:00
|
|
|
|
const {Circuit} = require('../models/circuit');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {Booking} = require('../models/booking');
|
|
|
|
|
|
const {Operator} = require('../models/operator');
|
|
|
|
|
|
const {Where} = require('../models/where');
|
|
|
|
|
|
const {MyEvent} = require('../models/myevent');
|
|
|
|
|
|
const {Contribtype} = require('../models/contribtype');
|
|
|
|
|
|
const {PaymentType} = require('../models/paymenttype');
|
|
|
|
|
|
const {Discipline} = require('../models/discipline');
|
2022-10-29 12:37:50 +02:00
|
|
|
|
const {MyElem} = require('../models/myelem');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {Skill} = require('../models/skill');
|
2022-02-21 13:12:27 +01:00
|
|
|
|
const {Good} = require('../models/good');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {StatusSkill} = require('../models/statusSkill');
|
2022-01-23 23:25:34 +01:00
|
|
|
|
const {Province} = require('../models/province');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {Sector} = require('../models/sector');
|
2022-02-21 13:12:27 +01:00
|
|
|
|
const {SectorGood} = require('../models/sectorgood');
|
2022-02-05 23:28:15 +01:00
|
|
|
|
const {CatGrp} = require('../models/catgrp');
|
2022-05-05 00:38:41 +02:00
|
|
|
|
const Site = require('../models/site');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {Level} = require('../models/level');
|
2022-02-12 02:20:07 +01:00
|
|
|
|
const {AdType} = require('../models/adtype');
|
2022-02-21 13:12:27 +01:00
|
|
|
|
const {AdTypeGood} = require('../models/adtypegood');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {Newstosent} = require('../models/newstosent');
|
|
|
|
|
|
const {MyPage} = require('../models/mypage');
|
|
|
|
|
|
const {CalZoom} = require('../models/calzoom');
|
|
|
|
|
|
const {Gallery} = require('../models/gallery');
|
|
|
|
|
|
const {Settings} = require('../models/settings');
|
|
|
|
|
|
const {SendMsg} = require('../models/sendmsg');
|
2022-07-10 01:25:19 +02:00
|
|
|
|
const {SendNotif} = require('../models/sendnotif');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {Permission} = require('../models/permission');
|
2020-12-25 03:54:16 +01:00
|
|
|
|
const Producer = require('../models/producer');
|
|
|
|
|
|
const Cart = require('../models/cart');
|
2021-01-18 00:48:17 +01:00
|
|
|
|
const OrdersCart = require('../models/orderscart');
|
2020-12-25 03:54:16 +01:00
|
|
|
|
const Storehouse = require('../models/storehouse');
|
2021-02-03 01:33:30 +01:00
|
|
|
|
const Department = require('../models/department');
|
|
|
|
|
|
const Group = require('../models/group');
|
2019-02-06 18:48:32 +01:00
|
|
|
|
|
2019-10-14 20:31:57 +02:00
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
|
const server_constants = require('../tools/server_constants');
|
|
|
|
|
|
const actions = require('./api/actions');
|
2019-02-06 18:48:32 +01:00
|
|
|
|
|
2020-05-04 19:34:41 +02:00
|
|
|
|
const shared_consts = require('../tools/shared_nodejs');
|
|
|
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const globalTables = require('../tools/globalTables');
|
|
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
const UserCost = {
|
2022-03-02 20:18:29 +01:00
|
|
|
|
FIELDS_UPDATE_TELEGRAM_BOT: [
|
|
|
|
|
|
'profile.teleg_id',
|
|
|
|
|
|
'profile.manage_telegram',
|
|
|
|
|
|
'deleted',
|
2022-08-04 17:30:57 +02:00
|
|
|
|
'reported',
|
2022-03-02 20:18:29 +01:00
|
|
|
|
],
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
FIELDS_REQUISITI: [
|
|
|
|
|
|
'verified_email',
|
2020-03-10 21:44:14 +01:00
|
|
|
|
'profile.teleg_id',
|
|
|
|
|
|
'profile.saw_and_accepted',
|
2020-09-04 00:06:49 +02:00
|
|
|
|
'profile.revolut',
|
|
|
|
|
|
'profile.payeer_id',
|
|
|
|
|
|
'profile.advcash_id',
|
|
|
|
|
|
'profile.link_payment',
|
2020-03-10 21:44:14 +01:00
|
|
|
|
'profile.email_paypal',
|
2021-11-22 18:29:22 +01:00
|
|
|
|
'profile.paymenttypes'],
|
2020-03-10 21:44:14 +01:00
|
|
|
|
};
|
2019-02-06 18:48:32 +01:00
|
|
|
|
|
2019-02-05 03:40:22 +01:00
|
|
|
|
router.post(process.env.LINKVERIF_REG, (req, res) => {
|
2019-10-20 01:21:54 +02:00
|
|
|
|
const body = _.pick(req.body, ['idapp', 'idlink']);
|
|
|
|
|
|
const idapp = body.idapp;
|
|
|
|
|
|
const idlink = body.idlink;
|
2019-02-05 03:40:22 +01:00
|
|
|
|
|
|
|
|
|
|
// Cerco l'idlink se è ancora da Verificare
|
|
|
|
|
|
|
|
|
|
|
|
User.findByLinkreg(idapp, idlink).then((user) => {
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
|
//console.log("NON TROVATO!");
|
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
|
} else {
|
2020-01-20 01:48:25 +01:00
|
|
|
|
console.log('user', user);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
if (user.verified_email) {
|
|
|
|
|
|
res.send({
|
|
|
|
|
|
code: server_constants.RIS_CODE_EMAIL_ALREADY_VERIFIED,
|
2021-11-22 18:29:22 +01:00
|
|
|
|
msg: tools.getres__('L\'Email è già stata Verificata', res),
|
2019-02-05 03:40:22 +01:00
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
user.verified_email = true;
|
2019-10-27 00:37:10 +02:00
|
|
|
|
user.lasttimeonline = new Date();
|
2019-02-05 03:40:22 +01:00
|
|
|
|
user.save().then(() => {
|
|
|
|
|
|
//console.log("TROVATOOOOOO!");
|
2020-03-10 21:44:14 +01:00
|
|
|
|
res.send({
|
|
|
|
|
|
code: server_constants.RIS_CODE_EMAIL_VERIFIED,
|
2021-11-22 18:29:22 +01:00
|
|
|
|
msg: tools.getres__('EMAIL', res) + ' ' +
|
|
|
|
|
|
tools.getres__('VERIF', res),
|
2020-03-10 21:44:14 +01:00
|
|
|
|
});
|
2019-02-05 03:40:22 +01:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch((e) => {
|
2022-02-22 15:24:32 +01:00
|
|
|
|
console.log(process.env.LINKVERIF_REG, e.message);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Faccio richiesta di una Nuova Password
|
2022-03-08 01:01:20 +01:00
|
|
|
|
router.post(process.env.LINK_REQUEST_NEWPASSWORD, async (req, res) => {
|
2019-10-23 23:47:21 +02:00
|
|
|
|
const body = _.pick(req.body, ['idapp', 'email']);
|
|
|
|
|
|
const idapp = body.idapp;
|
2020-03-10 21:44:14 +01:00
|
|
|
|
const email = body.email.toLowerCase().trim();
|
2021-11-22 18:29:22 +01:00
|
|
|
|
console.log(
|
|
|
|
|
|
'POST ' + process.env.LINK_REQUEST_NEWPASSWORD + ' idapp= ' + idapp +
|
|
|
|
|
|
' email = ' + email);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
|
2022-03-08 01:01:20 +01:00
|
|
|
|
try {
|
|
|
|
|
|
const ris = await User.createNewRequestPwd(idapp, email);
|
|
|
|
|
|
if (ris) {
|
|
|
|
|
|
res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tools.snooze(5000);
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.status(200).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_EMAIL_NOT_EXIST, msg: ''});
|
2019-02-05 03:40:22 +01:00
|
|
|
|
}
|
2022-07-10 01:25:19 +02:00
|
|
|
|
} catch (e) {
|
2022-02-22 15:24:32 +01:00
|
|
|
|
console.log(process.env.LINK_REQUEST_NEWPASSWORD, e.message);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
res.status(400).send();
|
2021-11-22 18:29:22 +01:00
|
|
|
|
res.send({code: server_constants.RIS_CODE_ERR, msg: e});
|
2022-03-08 01:01:20 +01:00
|
|
|
|
}
|
2019-02-05 03:40:22 +01:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Invio la Nuova Password richiesta dal reset!
|
|
|
|
|
|
// Ritorna il token per poter effettuare le chiamate...
|
2020-01-30 01:19:25 +01:00
|
|
|
|
router.post(process.env.LINK_UPDATE_PWD, (req, res) => {
|
|
|
|
|
|
const body = _.pick(req.body, ['idapp', 'email', 'tokenforgot', 'password']);
|
|
|
|
|
|
const idapp = body.idapp;
|
2020-03-10 21:44:14 +01:00
|
|
|
|
const email = body.email.toLowerCase().trim();
|
2020-01-30 01:19:25 +01:00
|
|
|
|
const tokenforgot = body.tokenforgot;
|
|
|
|
|
|
const password = body.password;
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const msg = 'Richiesta Nuova Password: idapp= ' + idapp + ' email = ' + email;
|
2020-01-30 01:19:25 +01:00
|
|
|
|
console.log(msg);
|
|
|
|
|
|
|
2020-02-19 16:09:16 +01:00
|
|
|
|
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
|
|
|
|
|
|
User.findByLinkTokenforgot(idapp, email, tokenforgot).then((user) => {
|
|
|
|
|
|
if (!user) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send(
|
|
|
|
|
|
{code: server_constants.RIS_CODE_TOKEN_RESETPASSWORD_NOT_FOUND});
|
2019-02-05 03:40:22 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
// aggiorna la nuova password
|
|
|
|
|
|
user.password = password;
|
2019-10-27 00:37:10 +02:00
|
|
|
|
user.lasttimeonline = new Date();
|
2019-02-05 03:40:22 +01:00
|
|
|
|
|
|
|
|
|
|
// Crea token
|
2019-02-09 18:03:14 +01:00
|
|
|
|
user.generateAuthToken(req).then(token => {
|
2019-02-05 03:40:22 +01:00
|
|
|
|
user.tokenforgot = ''; // Svuota il tokenforgot perché non ti servirà più...
|
|
|
|
|
|
|
|
|
|
|
|
// Salva lo User
|
|
|
|
|
|
user.save().then(() => {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
res.header('x-auth', token).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_OK}); // Ritorna il token di ritorno
|
2019-02-05 03:40:22 +01:00
|
|
|
|
});
|
2021-11-22 18:29:22 +01:00
|
|
|
|
});
|
2019-02-05 03:40:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
}).catch((e) => {
|
2022-02-22 15:24:32 +01:00
|
|
|
|
console.log(process.env.LINK_UPDATE_PWD, e.message);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
router.post('/testServer', authenticate_noerror, async (req, res) => {
|
2022-02-16 19:21:12 +01:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const test = req.body.test;
|
|
|
|
|
|
let ris = {test};
|
|
|
|
|
|
|
2022-02-22 18:27:59 +01:00
|
|
|
|
if (req.user) {
|
2022-09-11 11:45:33 +02:00
|
|
|
|
await tools.sendNotificationToUser(req.user._id, 'Test Server',
|
2022-02-28 03:33:47 +01:00
|
|
|
|
'Test Server OK',
|
|
|
|
|
|
'/', '', 'server', []);
|
2022-02-22 18:27:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
|
return res.send(ris);
|
|
|
|
|
|
} catch (e) {
|
2022-02-22 15:24:32 +01:00
|
|
|
|
console.error('testServer', e.message);
|
2022-02-16 19:21:12 +01:00
|
|
|
|
return res.status(400).send(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2022-09-16 17:38:49 +02:00
|
|
|
|
router.get('/test1', authenticate_noerror, async (req, res) => {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const test = req.query.test;
|
|
|
|
|
|
let ris = {test};
|
|
|
|
|
|
|
|
|
|
|
|
if (req.user) {
|
|
|
|
|
|
await tools.sendNotificationToUser(req.user._id, 'Test Server',
|
|
|
|
|
|
'Test Server OK',
|
|
|
|
|
|
'/', '', 'server', []);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res.send(ris);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error('testServer', e.message);
|
|
|
|
|
|
return res.status(400).send(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2022-02-28 17:20:47 +01:00
|
|
|
|
router.post('/settable', authenticate, async (req, res) => {
|
2019-10-20 01:21:54 +02:00
|
|
|
|
const params = req.body;
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const mytable = globalTables.getTableByTableName(params.table);
|
2022-09-03 13:06:58 +02:00
|
|
|
|
let mydata = req.body.data;
|
|
|
|
|
|
let extrarec = {};
|
2022-09-11 11:45:33 +02:00
|
|
|
|
if (mydata && mydata.hasOwnProperty('extrarec')) {
|
2022-09-03 13:06:58 +02:00
|
|
|
|
extrarec = mydata['extrarec'];
|
|
|
|
|
|
delete mydata['extrarec'];
|
|
|
|
|
|
}
|
2019-10-20 01:21:54 +02:00
|
|
|
|
|
2022-01-16 23:21:03 +01:00
|
|
|
|
const fieldsvalue = {'ALL': 1};
|
|
|
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
|
mydata.idapp = req.user.idapp;
|
2022-03-30 22:51:03 +02:00
|
|
|
|
const idapp = mydata.idapp;
|
2019-10-20 01:21:54 +02:00
|
|
|
|
|
2022-01-28 00:57:39 +01:00
|
|
|
|
let consentito = false;
|
2021-12-23 14:13:40 +01:00
|
|
|
|
|
2022-01-28 00:57:39 +01:00
|
|
|
|
try {
|
|
|
|
|
|
if (User.isAdmin(req.user.perm) || User.isManager(req.user.perm) ||
|
2022-07-28 21:47:23 +02:00
|
|
|
|
User.isEditor(req.user.perm) || User.isFacilitatore(req.user.perm)) {
|
2022-01-28 00:57:39 +01:00
|
|
|
|
consentito = true;
|
|
|
|
|
|
}
|
2021-10-08 00:38:35 +02:00
|
|
|
|
|
2022-01-28 00:57:39 +01:00
|
|
|
|
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
2022-07-28 21:47:23 +02:00
|
|
|
|
!User.isEditor(req.user.perm) && !User.isFacilitatore(req.user.perm)) &&
|
2022-01-28 00:57:39 +01:00
|
|
|
|
!tools.ModificheConsentite(params.table, fieldsvalue)) {
|
|
|
|
|
|
// If without permissions, exit
|
|
|
|
|
|
return res.status(404).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
|
|
|
|
|
}
|
2021-12-02 10:13:27 +01:00
|
|
|
|
|
2022-01-28 00:57:39 +01:00
|
|
|
|
if (shared_consts.TABLES_USER_ID.includes(params.table)) {
|
2022-02-05 23:28:15 +01:00
|
|
|
|
if (!mydata.userId)
|
|
|
|
|
|
mydata.userId = req.user._id;
|
2022-01-28 00:57:39 +01:00
|
|
|
|
}
|
2021-10-08 00:38:35 +02:00
|
|
|
|
|
2022-08-04 17:30:57 +02:00
|
|
|
|
if (shared_consts.TABLES_CREATEDBY.includes(params.table)) {
|
|
|
|
|
|
if (!mydata.createdBy)
|
|
|
|
|
|
mydata.createdBy = req.user.username;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-15 15:10:27 +02:00
|
|
|
|
if (shared_consts.TABLES_UPDATE_LASTMODIFIED.includes(params.table)) {
|
|
|
|
|
|
mydata.date_updated = new Date();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-28 00:57:39 +01:00
|
|
|
|
if (shared_consts.TABLES_PERM_NEWREC.includes(params.table)) {
|
|
|
|
|
|
if (!consentito) {
|
|
|
|
|
|
mydata.verifyrec = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-10-08 00:38:35 +02:00
|
|
|
|
|
2022-02-05 23:28:15 +01:00
|
|
|
|
if (params.table === shared_consts.TAB_MYGROUPS) {
|
|
|
|
|
|
if (shared_consts.MYGROUPS_KEY_TO_CRYPTED in mydata) {
|
|
|
|
|
|
if (mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]) {
|
2022-02-16 09:40:16 +01:00
|
|
|
|
mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED +
|
|
|
|
|
|
shared_consts.SUFFIX_CRYPTED] = tools.cryptdata(
|
|
|
|
|
|
mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]);
|
2022-02-05 23:28:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-03 00:33:15 +01:00
|
|
|
|
if (shared_consts.TABLES_USER_INCLUDE_MY.includes(params.table)) {
|
2022-09-02 02:25:38 +02:00
|
|
|
|
if (!mydata.admins || mydata.admins.length <= 0) {
|
2022-02-28 00:07:47 +01:00
|
|
|
|
// Aggiungi solo se non esistono Admin:
|
2022-02-03 00:33:15 +01:00
|
|
|
|
mydata.admins = [];
|
2022-02-28 00:07:47 +01:00
|
|
|
|
const indfind = mydata.admins.findIndex(
|
|
|
|
|
|
(rec) => (rec.username === req.user.username));
|
2022-02-03 00:33:15 +01:00
|
|
|
|
|
2022-02-28 00:07:47 +01:00
|
|
|
|
if (indfind < 0) {
|
|
|
|
|
|
mydata.admins.push({username: req.user.username});
|
|
|
|
|
|
}
|
2022-02-03 00:33:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-28 00:57:39 +01:00
|
|
|
|
delete mydata['__v'];
|
|
|
|
|
|
delete mydata['__proto__'];
|
|
|
|
|
|
|
|
|
|
|
|
let mytablerec = new mytable(mydata);
|
|
|
|
|
|
// console.log('mytablerec', mytablerec);
|
2021-12-02 10:13:27 +01:00
|
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const mytablestrutt = globalTables.getTableByTableName(params.table);
|
2021-12-21 01:27:45 +01:00
|
|
|
|
|
2022-01-28 00:57:39 +01:00
|
|
|
|
if (mydata['_id'] !== undefined && mydata['_id'] !== 0) {
|
|
|
|
|
|
mytablerec.isNew = false;
|
2021-12-21 01:27:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-14 11:32:04 +02:00
|
|
|
|
if (shared_consts.TABLES_ID_NUMBER.includes(params.table) ||
|
|
|
|
|
|
shared_consts.TABLES_ID_STRING.includes(params.table)) {
|
2022-09-03 13:06:58 +02:00
|
|
|
|
|
2022-01-28 00:57:39 +01:00
|
|
|
|
} else if (params.table === 'hours') {
|
2021-10-08 00:38:35 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
} else {
|
2022-11-10 19:33:23 +01:00
|
|
|
|
if ((mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) && (mytablerec._id === undefined)) {
|
2022-09-19 19:40:30 +02:00
|
|
|
|
mytablerec._id = new ObjectID();
|
2022-01-28 00:57:39 +01:00
|
|
|
|
}
|
2021-11-22 18:29:22 +01:00
|
|
|
|
}
|
2022-01-28 00:57:39 +01:00
|
|
|
|
|
2022-02-28 17:20:47 +01:00
|
|
|
|
const isnewrec = mytablerec.isNew;
|
|
|
|
|
|
|
|
|
|
|
|
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
|
|
|
|
|
|
// Controlla se esiste già con lo stesso nome
|
|
|
|
|
|
let alreadyexist = await MyGroup.findOne({idapp, groupname: mydata.groupname});
|
|
|
|
|
|
if (alreadyexist) {
|
2022-07-10 01:25:19 +02:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_CODE});
|
2022-02-28 17:20:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
alreadyexist = await MyGroup.findOne({idapp, title: mydata.title});
|
|
|
|
|
|
if (alreadyexist) {
|
2022-07-10 01:25:19 +02:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_NAME});
|
2022-02-28 17:20:47 +01:00
|
|
|
|
}
|
2022-09-02 02:25:38 +02:00
|
|
|
|
} else if (params.table === shared_consts.TAB_MYCIRCUITS && isnewrec) {
|
|
|
|
|
|
// Controlla se esiste già con lo stesso nome
|
|
|
|
|
|
let alreadyexist = await Circuit.findOne({idapp, name: mydata.name});
|
|
|
|
|
|
if (alreadyexist) {
|
|
|
|
|
|
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_CODE});
|
|
|
|
|
|
}
|
|
|
|
|
|
alreadyexist = await Circuit.findOne({idapp, path: mydata.path});
|
|
|
|
|
|
if (alreadyexist) {
|
|
|
|
|
|
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_NAME});
|
|
|
|
|
|
}
|
2022-09-14 17:37:29 +02:00
|
|
|
|
/*alreadyexist = await Circuit.findOne({idapp, symbol: mydata.symbol});
|
2022-09-12 18:37:08 +02:00
|
|
|
|
if (alreadyexist) {
|
|
|
|
|
|
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_SYMBOL});
|
|
|
|
|
|
}
|
2022-09-14 17:37:29 +02:00
|
|
|
|
|
|
|
|
|
|
*/
|
2022-02-28 17:20:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 00:48:33 +01:00
|
|
|
|
if (shared_consts.TABLES_UPDATE_LASTMODIFIED.includes(params.table)) {
|
|
|
|
|
|
mytablerec.date_updated = new Date();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-18 20:17:24 +02:00
|
|
|
|
// console.log('mydata',mydata);
|
2022-09-14 11:32:04 +02:00
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
return await mytablerec.save().
|
2022-02-16 09:40:16 +01:00
|
|
|
|
then(async (rec) => {
|
2022-01-28 00:57:39 +01:00
|
|
|
|
|
2022-02-16 09:40:16 +01:00
|
|
|
|
if (shared_consts.TABLES_GETCOMPLETEREC.includes(params.table)) {
|
2022-02-28 17:20:47 +01:00
|
|
|
|
return await mytablestrutt.getCompleteRecord(rec.idapp, rec._id);
|
2022-02-16 09:40:16 +01:00
|
|
|
|
} else {
|
2022-02-28 17:20:47 +01:00
|
|
|
|
return rec;
|
2022-02-16 09:40:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// tools.mylog('rec', rec);
|
2022-07-28 23:27:51 +02:00
|
|
|
|
}).then(async (myrec) => {
|
2022-02-16 09:40:16 +01:00
|
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
|
let setnotif = false;
|
|
|
|
|
|
let typedir = 0;
|
|
|
|
|
|
let typeid = 0;
|
2022-08-04 17:30:57 +02:00
|
|
|
|
let groupnameDest = '';
|
2022-09-02 02:25:38 +02:00
|
|
|
|
let circuitnameDest = '';
|
2022-07-26 15:46:39 +02:00
|
|
|
|
|
2022-08-10 17:07:02 +02:00
|
|
|
|
if (isnewrec) {
|
|
|
|
|
|
// New Record created
|
|
|
|
|
|
|
|
|
|
|
|
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) {
|
|
|
|
|
|
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
|
|
|
|
|
|
typeid = (params.table === shared_consts.TABLES_MYGOODS)
|
|
|
|
|
|
? shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD
|
2022-09-03 13:06:58 +02:00
|
|
|
|
: shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE;
|
2022-08-10 17:07:02 +02:00
|
|
|
|
setnotif = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (shared_consts.TABLES_EVENTS_NOTIFICATION.includes(params.table)) {
|
|
|
|
|
|
typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS;
|
|
|
|
|
|
typeid = shared_consts.TypeNotifs.ID_EVENTS_NEW_REC;
|
|
|
|
|
|
setnotif = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(params.table)) {
|
|
|
|
|
|
typedir = shared_consts.TypeNotifs.TYPEDIR_GROUPS;
|
|
|
|
|
|
typeid = shared_consts.TypeNotifs.ID_GROUP_NEW_REC;
|
|
|
|
|
|
groupnameDest = myrec ? myrec.groupname : '';
|
|
|
|
|
|
setnotif = true;
|
|
|
|
|
|
}
|
2022-09-02 02:25:38 +02:00
|
|
|
|
if (shared_consts.TABLES_CIRCUITS_NOTIFICATION.includes(params.table)) {
|
|
|
|
|
|
typedir = shared_consts.TypeNotifs.TYPEDIR_CIRCUITS;
|
2022-09-14 17:37:29 +02:00
|
|
|
|
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
|
2022-09-02 02:25:38 +02:00
|
|
|
|
circuitnameDest = myrec ? myrec.name : '';
|
2022-09-19 14:37:57 +02:00
|
|
|
|
setnotif = (myrec.visibility === 0); // Not send a notification to others if the Circuit is HIDDEN or PRIVATE
|
2022-09-02 02:25:38 +02:00
|
|
|
|
}
|
2022-07-28 21:47:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-26 15:46:39 +02:00
|
|
|
|
if (setnotif) {
|
2022-09-02 02:25:38 +02:00
|
|
|
|
await SendNotif.createNewNotification(req, res, {groupnameDest, circuitnameDest}, params.table, myrec, typedir, typeid);
|
2022-07-23 17:48:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-06 13:39:01 +01:00
|
|
|
|
if (params.table === 'circuits') {
|
|
|
|
|
|
await Circuit.updateData(myrec.idapp, myrec.name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-28 23:27:51 +02:00
|
|
|
|
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
|
|
|
|
|
|
// nuovo Record:
|
|
|
|
|
|
// aggiungi il creatore al gruppo stesso
|
2022-09-11 11:45:33 +02:00
|
|
|
|
return await User.setGroupsCmd(mydata.idapp, req.user.username,
|
2022-07-28 23:27:51 +02:00
|
|
|
|
myrec.groupname,
|
|
|
|
|
|
shared_consts.GROUPSCMD.SETGROUP, true, req.user.username).then((ris) => {
|
2022-09-14 17:37:29 +02:00
|
|
|
|
return res.send({rec: myrec, ris});
|
2022-07-28 23:27:51 +02:00
|
|
|
|
});
|
2022-09-02 02:25:38 +02:00
|
|
|
|
} else if (params.table === shared_consts.TAB_MYCIRCUITS && isnewrec) {
|
|
|
|
|
|
// nuovo Record:
|
|
|
|
|
|
// aggiungi il creatore al Circuito stesso
|
2022-09-11 11:45:33 +02:00
|
|
|
|
return await User.setCircuitCmd(mydata.idapp, req.user.username, myrec.name,
|
2022-09-03 13:06:58 +02:00
|
|
|
|
shared_consts.CIRCUITCMD.SET, true, req.user.username, extrarec).then((ris) => {
|
2022-09-14 17:37:29 +02:00
|
|
|
|
return res.send({rec: myrec, ris});
|
2022-09-02 02:25:38 +02:00
|
|
|
|
});
|
2022-07-28 23:27:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-14 17:37:29 +02:00
|
|
|
|
return res.send({rec: myrec, ris: null});
|
2022-09-11 11:45:33 +02:00
|
|
|
|
}).catch(async (e) => {
|
2022-02-22 15:24:32 +01:00
|
|
|
|
console.error('settable', e.message);
|
2022-02-16 09:40:16 +01:00
|
|
|
|
if (e.code === 11000) {
|
|
|
|
|
|
const id = mytablerec._id;
|
|
|
|
|
|
delete mytablerec._doc['_id'];
|
|
|
|
|
|
const myfields = mytablerec._doc;
|
|
|
|
|
|
if (!myfields.userId) {
|
|
|
|
|
|
myfields.userId = req.user._id.toString();
|
|
|
|
|
|
}
|
2022-09-11 11:45:33 +02:00
|
|
|
|
return await mytablestrutt.findByIdAndUpdate(id, {$set: myfields}).
|
2022-02-16 09:40:16 +01:00
|
|
|
|
then(async (rec) => {
|
2022-09-14 17:37:29 +02:00
|
|
|
|
return res.send({rec});
|
2022-02-16 09:40:16 +01:00
|
|
|
|
}).
|
|
|
|
|
|
catch((err) => {
|
|
|
|
|
|
tools.mylog('error: ', err.message);
|
|
|
|
|
|
return res.status(400).send(err);
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log(e.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2022-01-28 00:57:39 +01:00
|
|
|
|
|
2022-02-03 00:33:15 +01:00
|
|
|
|
} catch (e) {
|
2022-02-22 15:24:32 +01:00
|
|
|
|
console.error('settable', e.message);
|
2022-01-28 00:57:39 +01:00
|
|
|
|
return res.status(400).send(e);
|
|
|
|
|
|
}
|
2021-10-08 00:38:35 +02:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
router.post('/setsubrec', authenticate, (req, res) => {
|
|
|
|
|
|
const params = req.body;
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const mytable = globalTables.getTableByTableName(params.table);
|
2021-10-08 00:38:35 +02:00
|
|
|
|
const mydata = req.body.data;
|
|
|
|
|
|
|
|
|
|
|
|
mydata.idapp = req.user.idapp;
|
2019-10-28 16:01:28 +01:00
|
|
|
|
|
2021-01-18 00:48:17 +01:00
|
|
|
|
let mytablerec = new mytable(mydata);
|
2021-10-05 00:20:12 +02:00
|
|
|
|
// console.log('mytablerec', mytablerec);
|
2019-10-28 16:01:28 +01:00
|
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const mytablestrutt = globalTables.getTableByTableName(params.table);
|
2019-10-20 01:21:54 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const rec = mytablestrutt.createNewSubRecord(mydata.idapp, req).then(rec => {
|
2021-10-08 00:38:35 +02:00
|
|
|
|
// tools.mylog('rec', rec);
|
|
|
|
|
|
return res.send(rec);
|
|
|
|
|
|
|
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return res.send(rec);
|
|
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return mytablerec.save().then(rec => {
|
|
|
|
|
|
// tools.mylog('rec', rec);
|
|
|
|
|
|
return res.send(rec);
|
2019-10-20 01:21:54 +02:00
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
}).catch((e) => {
|
|
|
|
|
|
if (e.code === 11000) {
|
|
|
|
|
|
const id = mytablerec._id;
|
|
|
|
|
|
delete mytablerec._doc['_id'];
|
|
|
|
|
|
const myfields = mytablerec._doc;
|
|
|
|
|
|
if (!myfields.userId) {
|
|
|
|
|
|
myfields.userId = req.user._id.toString();
|
2021-02-11 02:20:35 +01:00
|
|
|
|
}
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return mytablestrutt.findByIdAndUpdate(id, {$set: myfields}).
|
|
|
|
|
|
then(async (rec) => {
|
|
|
|
|
|
return res.send(rec);
|
|
|
|
|
|
}).
|
|
|
|
|
|
catch((err) => {
|
|
|
|
|
|
tools.mylog('error: ', err.message);
|
|
|
|
|
|
return res.status(400).send(err);
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log(e.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-10-20 01:21:54 +02:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2019-10-15 20:40:31 +02:00
|
|
|
|
router.post('/gettable', authenticate, (req, res) => {
|
|
|
|
|
|
const params = req.body;
|
2022-02-28 03:33:47 +01:00
|
|
|
|
let idapp = req.user.idapp;
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const mytable = globalTables.getTableByTableName(params.table);
|
2019-10-20 01:21:54 +02:00
|
|
|
|
// console.log('mytable', mytable);
|
|
|
|
|
|
if (!mytable) {
|
2019-12-04 02:03:44 +01:00
|
|
|
|
console.log(`Table ${params.table} not found`);
|
|
|
|
|
|
return res.status(400).send({});
|
2019-10-20 01:21:54 +02:00
|
|
|
|
}
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2022-02-22 15:24:32 +01:00
|
|
|
|
try {
|
2019-10-20 01:21:54 +02:00
|
|
|
|
|
2022-02-27 16:56:02 +01:00
|
|
|
|
return mytable.executeQueryTable(idapp, params, req.user).then(ris => {
|
2022-02-22 15:24:32 +01:00
|
|
|
|
return res.send(ris);
|
|
|
|
|
|
|
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
|
console.error('gettable: ' + e.message);
|
|
|
|
|
|
res.status(400).send(e);
|
|
|
|
|
|
});
|
2022-02-28 03:33:47 +01:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error(`ERROR gettable ${params.table}: `, e.message, 'params',
|
|
|
|
|
|
params);
|
2022-02-22 15:24:32 +01:00
|
|
|
|
res.status(500).send(e);
|
|
|
|
|
|
}
|
2019-10-14 20:31:57 +02:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2022-07-10 01:25:19 +02:00
|
|
|
|
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) &&
|
2022-07-28 21:47:23 +02:00
|
|
|
|
!User.isFacilitatore(req.user.perm))) {
|
2022-07-10 01:25:19 +02:00
|
|
|
|
// 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,
|
2022-08-04 17:30:57 +02:00
|
|
|
|
'reported': 1,
|
2022-08-09 17:32:06 +02:00
|
|
|
|
date_report: 1,
|
|
|
|
|
|
username_who_report: 1,
|
2022-07-10 01:25:19 +02:00
|
|
|
|
'profile.teleg_id': 1,
|
|
|
|
|
|
'verified_by_aportador': 1,
|
|
|
|
|
|
'profile.username_telegram': 1,
|
|
|
|
|
|
'profile.firstname_telegram': 1,
|
|
|
|
|
|
'profile.lastname_telegram': 1,
|
|
|
|
|
|
}).then(ris => {
|
|
|
|
|
|
|
2022-07-11 23:20:28 +02:00
|
|
|
|
return res.send(ris);
|
2022-07-10 01:25:19 +02:00
|
|
|
|
|
|
|
|
|
|
}).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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-12-21 01:27:45 +01:00
|
|
|
|
router.post('/pickup', authenticate, (req, res) => {
|
|
|
|
|
|
const params = req.body;
|
2022-02-28 03:33:47 +01:00
|
|
|
|
let idapp = req.user.idapp;
|
2022-02-16 19:21:12 +01:00
|
|
|
|
let mytable = globalTables.getTableByTableName(params.table);
|
2021-12-21 01:27:45 +01:00
|
|
|
|
// console.log('mytable', mytable);
|
2022-01-20 00:39:06 +01:00
|
|
|
|
if (!mytable) {
|
2021-12-21 01:27:45 +01:00
|
|
|
|
console.log(`Table ${params.table} not found`);
|
|
|
|
|
|
return res.status(400).send({});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-27 16:56:02 +01:00
|
|
|
|
return mytable.executeQueryPickup(idapp, params).then(ris => {
|
2021-12-21 01:27:45 +01:00
|
|
|
|
return res.send(ris);
|
|
|
|
|
|
|
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
|
console.log(e.message);
|
|
|
|
|
|
res.status(400).send(e);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-04-30 01:31:12 +02:00
|
|
|
|
router.post('/getpage', async (req, res) => {
|
|
|
|
|
|
const params = req.body;
|
|
|
|
|
|
const idapp = req.body.idapp;
|
|
|
|
|
|
const mypath = params.path;
|
|
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
return await MyPage.findOne({idapp, path: mypath}).then((ris) => {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send({mypage: ris});
|
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
|
console.log(e.message);
|
|
|
|
|
|
res.status(400).send(e);
|
|
|
|
|
|
});
|
2021-04-30 01:31:12 +02:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-03-31 20:34:24 +02:00
|
|
|
|
router.patch('/setlang', authenticate, async (req, res) => {
|
|
|
|
|
|
const username = req.body.data.username;
|
2022-02-27 16:56:02 +01:00
|
|
|
|
const idapp = req.user.idapp;
|
2020-03-31 20:34:24 +02:00
|
|
|
|
const mydata = req.body.data;
|
|
|
|
|
|
|
|
|
|
|
|
const lang = mydata.lang;
|
|
|
|
|
|
|
|
|
|
|
|
const fieldsvalue = {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
lang,
|
2020-03-31 20:34:24 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (!!lang) {
|
|
|
|
|
|
const rec = await User.findByUsername(idapp, username, false);
|
|
|
|
|
|
let ris = null;
|
|
|
|
|
|
if (!!rec)
|
2021-11-22 18:29:22 +01:00
|
|
|
|
ris = await User.findByIdAndUpdate(rec.id, {$set: fieldsvalue});
|
2020-03-31 20:34:24 +02:00
|
|
|
|
|
|
|
|
|
|
if (!!ris) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
2020-03-31 20:34:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
|
router.patch('/chval', authenticate, async (req, res) => {
|
2019-10-15 20:40:31 +02:00
|
|
|
|
// const idapp = req.body.idapp;
|
|
|
|
|
|
const id = req.body.data.id;
|
2022-02-27 16:56:02 +01:00
|
|
|
|
const idapp = req.user.idapp;
|
2019-10-15 20:40:31 +02:00
|
|
|
|
const mydata = req.body.data;
|
|
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
try {
|
|
|
|
|
|
const mytable = globalTables.getTableByTableName(mydata.table);
|
|
|
|
|
|
const fieldsvalue = mydata.fieldsvalue;
|
|
|
|
|
|
const unset = mydata.unset;
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
// tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
// If I change my record...
|
|
|
|
|
|
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
2022-07-28 21:47:23 +02:00
|
|
|
|
!User.isEditor(req.user.perm) && !User.isFacilitatore(req.user.perm)) &&
|
2022-02-28 03:33:47 +01:00
|
|
|
|
(req.user._id.toString() !== id) &&
|
|
|
|
|
|
!tools.ModificheConsentite(mydata.table, fieldsvalue)) {
|
|
|
|
|
|
// If without permissions, exit
|
|
|
|
|
|
return res.status(404).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
2020-03-10 21:44:14 +01:00
|
|
|
|
}
|
2020-07-02 22:00:58 +02:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
const camporequisiti = UserCost.FIELDS_REQUISITI.includes(
|
|
|
|
|
|
Object.keys(fieldsvalue)[0]);
|
|
|
|
|
|
|
|
|
|
|
|
let allData = {};
|
2022-03-04 15:30:11 +01:00
|
|
|
|
let username = '';
|
2022-02-28 03:33:47 +01:00
|
|
|
|
if (mydata.table === 'users') {
|
|
|
|
|
|
if (camporequisiti) {
|
|
|
|
|
|
allData = {};
|
|
|
|
|
|
allData.myuser = await User.getUserById(idapp, id);
|
2022-03-04 15:30:11 +01:00
|
|
|
|
username = allData.myuser.username;
|
2022-02-28 03:33:47 +01:00
|
|
|
|
if (!!allData.myuser)
|
|
|
|
|
|
allData.precDataUser = await User.getInfoUser(idapp,
|
|
|
|
|
|
allData.myuser.username);
|
|
|
|
|
|
else
|
|
|
|
|
|
allData.precDataUser = null;
|
|
|
|
|
|
// allData.useraportador = await ListaIngresso.getUserByInvitante_Username(idapp, allData.myuser.aportador_solidario);
|
|
|
|
|
|
// allData.precDataAportador = await getInfoUser(idapp, allData.myuser.aportador_solidario);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-07-02 22:00:58 +02:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
let index = 0;
|
2020-07-02 22:00:58 +02:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
let recoldnave = null;
|
2021-10-08 00:38:35 +02:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
let myuser = null;
|
|
|
|
|
|
let mydatamsg = {};
|
2021-12-03 22:48:05 +01:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
let flotta = null;
|
|
|
|
|
|
let strflotta = '';
|
2022-02-27 16:56:02 +01:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
if (shared_consts.TABLES_UPDATE_LASTMODIFIED.includes(mydata.table)) {
|
|
|
|
|
|
fieldsvalue.date_updated = new Date();
|
2021-12-23 14:13:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
const numobj = tools.getNumObj(fieldsvalue);
|
|
|
|
|
|
if (numobj === 1 && fieldsvalue['_id']) {
|
|
|
|
|
|
const myrec = await mytable.findById(id);
|
|
|
|
|
|
const myidDel = myrec['_id'];
|
|
|
|
|
|
myrec['_id'] = fieldsvalue['_id'];
|
|
|
|
|
|
return await mytable.insertMany(myrec).then((ris) => {
|
|
|
|
|
|
if (ris) {
|
|
|
|
|
|
return mytable.deleteMany({_id: myidDel}).then((risdel) => {
|
|
|
|
|
|
return res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2022-01-07 01:18:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-02 20:18:29 +01:00
|
|
|
|
const updatebot = UserCost.FIELDS_UPDATE_TELEGRAM_BOT.includes(Object.keys(fieldsvalue)[0]);
|
|
|
|
|
|
|
2022-03-04 15:30:11 +01:00
|
|
|
|
tools.refreshAllTablesInMem(idapp, mydata.table, updatebot, username);
|
2022-01-07 01:18:01 +01:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
if (mydata.table === shared_consts.TAB_SETTINGS) {
|
|
|
|
|
|
if (shared_consts.KEY_TO_CRYPTED.includes(fieldsvalue.key)) {
|
|
|
|
|
|
fieldsvalue.crypted = true;
|
|
|
|
|
|
fieldsvalue.value_str = tools.cryptdata(fieldsvalue.value_str);
|
2020-02-02 04:06:32 +01:00
|
|
|
|
}
|
2022-02-28 03:33:47 +01:00
|
|
|
|
}
|
2020-02-05 00:39:25 +01:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
if (mydata.table === shared_consts.TAB_SITES) {
|
|
|
|
|
|
if (shared_consts.SITES_KEY_TO_CRYPTED in fieldsvalue) {
|
|
|
|
|
|
fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED] = tools.cryptdata(
|
|
|
|
|
|
fieldsvalue[shared_consts.SITES_KEY_TO_CRYPTED]);
|
|
|
|
|
|
}
|
2020-09-04 00:06:49 +02:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
}
|
2020-05-10 21:07:51 +02:00
|
|
|
|
|
2022-03-04 22:30:50 +01:00
|
|
|
|
return await mytable.findByIdAndUpdate(id, {$set: fieldsvalue}).
|
2022-02-28 03:33:47 +01:00
|
|
|
|
then(async (rec) => {
|
|
|
|
|
|
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
|
|
|
|
|
if (!rec) {
|
|
|
|
|
|
return res.status(404).send();
|
2020-05-04 19:34:41 +02:00
|
|
|
|
} else {
|
2022-02-28 03:33:47 +01:00
|
|
|
|
let addmsg = '';
|
|
|
|
|
|
|
|
|
|
|
|
if (mydata.notifBot) {
|
|
|
|
|
|
// Send Notification to the BOT
|
|
|
|
|
|
await telegrambot.sendMsgTelegram(idapp, mydata.notifBot.un,
|
|
|
|
|
|
mydata.notifBot.txt);
|
|
|
|
|
|
if (!!addmsg)
|
|
|
|
|
|
await telegrambot.sendMsgTelegram(idapp, mydata.notifBot.un,
|
|
|
|
|
|
addmsg);
|
|
|
|
|
|
let addtext = '[Msg Inviato a ' + mydata.notifBot.un + ']:' +
|
|
|
|
|
|
'\n' +
|
|
|
|
|
|
mydata.notifBot.txt;
|
|
|
|
|
|
telegrambot.sendMsgTelegramToTheManagers(idapp, addtext, true);
|
|
|
|
|
|
|
|
|
|
|
|
if (!!flotta)
|
|
|
|
|
|
tools.writeFlottaLog(idapp, addtext, flotta.riga,
|
|
|
|
|
|
flotta.col_prima);
|
2020-03-10 21:44:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-18 01:21:04 +02:00
|
|
|
|
if (mydata.table === 'accounts') {
|
|
|
|
|
|
if ('saldo' in fieldsvalue) {
|
|
|
|
|
|
msg = 'l\'utente ' + req.user.username + ' ha variato il Saldo di ' + rec.username + ' a ' + fieldsvalue.saldo;
|
|
|
|
|
|
telegrambot.sendMsgTelegramToTheManagers(idapp, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-06 13:39:01 +01:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
if (mydata.table === 'users') {
|
|
|
|
|
|
if (camporequisiti) {
|
|
|
|
|
|
await User.checkIfSbloccatiRequisiti(idapp, allData, id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ('aportador_solidario' in fieldsvalue) {
|
|
|
|
|
|
let ind_order_ingr = mydata.ind_order_ingr;
|
|
|
|
|
|
// SERVE SE CI METTO LE MINUSCOLE/MAIUSCOLE SBAGLIATE in invitante_username!
|
|
|
|
|
|
const myuserfound = await User.findByUsername(idapp,
|
|
|
|
|
|
fieldsvalue.aportador_solidario, false);
|
|
|
|
|
|
if (!!myuserfound) {
|
|
|
|
|
|
if (!!myuserfound._id && !myuserfound.deleted) {
|
|
|
|
|
|
const aportador = await User.getUsernameById(idapp,
|
|
|
|
|
|
myuserfound._id);
|
|
|
|
|
|
fieldsvalue.aportador_solidario = aportador;
|
|
|
|
|
|
//Aggiorna record !
|
|
|
|
|
|
await mytable.findByIdAndUpdate(id, {$set: fieldsvalue});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
res.send(
|
|
|
|
|
|
{
|
|
|
|
|
|
code: server_constants.RIS_CODE_ERR,
|
|
|
|
|
|
msg: 'Non aggiornato',
|
|
|
|
|
|
});
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if ('deleted' in fieldsvalue) {
|
|
|
|
|
|
let msg = '';
|
|
|
|
|
|
if (fieldsvalue.deleted)
|
|
|
|
|
|
msg = 'cancellato (nascosto)';
|
|
|
|
|
|
else
|
|
|
|
|
|
msg = 'Ripristinato';
|
|
|
|
|
|
|
|
|
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(idapp,
|
|
|
|
|
|
`L\'utente ` + tools.getNomeCognomeEUserNameByUser(rec) +
|
|
|
|
|
|
` è stato ${msg} da ` +
|
|
|
|
|
|
tools.getNomeCognomeEUserNameByUser(req.user));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-02-05 00:39:25 +01:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
if (tools.ModificheConsentite(mydata.table, fieldsvalue)) {
|
|
|
|
|
|
let msg = '';
|
|
|
|
|
|
if (mydata.table === 'users') {
|
|
|
|
|
|
if ('aportador_solidario' in fieldsvalue) {
|
|
|
|
|
|
const nomecognomenuovo = await User.getNameSurnameByUsername(
|
|
|
|
|
|
idapp,
|
|
|
|
|
|
fieldsvalue.aportador_solidario);
|
|
|
|
|
|
const nomecognomeas = await User.getNameSurnameByUsername(
|
|
|
|
|
|
idapp,
|
|
|
|
|
|
rec.aportador_solidario);
|
|
|
|
|
|
msg = `Variato l'invitante di ` +
|
|
|
|
|
|
tools.getNomeCognomeEUserNameByUser(rec) +
|
|
|
|
|
|
'\nmodificato da ' +
|
|
|
|
|
|
tools.getNomeCognomeEUserNameByUser(req.user) +
|
|
|
|
|
|
' \n' +
|
|
|
|
|
|
'Prima: ' + nomecognomeas + ' (' +
|
|
|
|
|
|
rec.aportador_solidario +
|
|
|
|
|
|
')\n' +
|
|
|
|
|
|
'Dopo: ' + nomecognomenuovo + ' (' +
|
|
|
|
|
|
fieldsvalue.aportador_solidario + ') ]';
|
|
|
|
|
|
|
|
|
|
|
|
// Metti l'iniziale
|
|
|
|
|
|
if (!await User.AportadorOrig(id)) {
|
|
|
|
|
|
await mytable.findByIdAndUpdate(id,
|
|
|
|
|
|
{$set: {aportador_iniziale: fieldsvalue.aportador_solidario}},
|
|
|
|
|
|
{new: false});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (msg !== '')
|
|
|
|
|
|
telegrambot.sendMsgTelegramToTheManagers(idapp, msg);
|
|
|
|
|
|
}
|
2020-02-05 00:39:25 +01:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
2020-02-02 04:06:32 +01:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
}
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2022-02-28 03:33:47 +01:00
|
|
|
|
}).
|
|
|
|
|
|
catch((e) => {
|
|
|
|
|
|
tools.mylogserr('Error patch USER: ', e.message);
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
tools.mylogserr('Error chval: ', e.message);
|
2019-10-15 20:40:31 +02:00
|
|
|
|
res.status(400).send();
|
2022-02-28 03:33:47 +01:00
|
|
|
|
}
|
2020-05-10 21:07:51 +02:00
|
|
|
|
|
2019-10-15 20:40:31 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2020-05-19 00:18:13 +02:00
|
|
|
|
router.patch('/askfunz', authenticate, async (req, res) => {
|
|
|
|
|
|
// const idapp = req.body.idapp;
|
|
|
|
|
|
const id = req.body.data.id;
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// const ind_order = req.body.data.ind_order;
|
|
|
|
|
|
// const username = req.body.data.username;
|
2022-02-27 16:56:02 +01:00
|
|
|
|
const idapp = req.user.idapp;
|
2020-05-19 00:18:13 +02:00
|
|
|
|
const mydata = req.body.data;
|
|
|
|
|
|
|
|
|
|
|
|
let entra = false;
|
|
|
|
|
|
if (!entra) {
|
|
|
|
|
|
// If I change my record...
|
2021-11-22 18:29:22 +01:00
|
|
|
|
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
2022-07-28 21:47:23 +02:00
|
|
|
|
!User.isFacilitatore(req.user.perm)) && (req.user._id.toString() !== id)) {
|
2020-05-19 00:18:13 +02:00
|
|
|
|
// If without permissions, exit
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.status(404).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
2020-05-19 00:18:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mydata.myfunc === shared_consts.CallFunz.DAMMI_PRIMO_UTENTE_LIBERO) {
|
|
|
|
|
|
const userfree = await Graduatoria.getFirstUserGradFree(idapp);
|
|
|
|
|
|
|
|
|
|
|
|
if (!!userfree)
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_OK, out: userfree});
|
2020-06-08 13:31:05 +02:00
|
|
|
|
/*} else if (mydata.myfunc === shared_consts.CallFunz.GET_VALBYTABLE) {
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const mytable = globalTables.getTableByTableName(mydata.table);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
const coltoshow = {
|
|
|
|
|
|
[mydata.coltoshow]: 1
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const ris = await mytable.findOne({ _id: id }, coltoshow);
|
|
|
|
|
|
|
|
|
|
|
|
return ris;
|
|
|
|
|
|
} else if (mydata.myfunc === shared_consts.CallFunz.SET_VALBYTABLE) {
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const mytable = globalTables.getTableByTableName(mydata.table);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
const value = mydata.value;
|
|
|
|
|
|
const coltoset = {
|
|
|
|
|
|
[mydata.coltoshow]: value
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const ris = await mytable.findOneAndUpdate({ _id: id }, { $set: coltoset }, { new: false });
|
|
|
|
|
|
if (!!ris)
|
|
|
|
|
|
return res.send({ code: server_constants.RIS_CODE_OK });*/
|
2020-05-19 00:18:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_ERR});
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
2020-05-19 00:18:13 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
router.patch('/callfunz', authenticate, async (req, res) => {
|
|
|
|
|
|
// const idapp = req.body.idapp;
|
|
|
|
|
|
const id = req.body.data.id;
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// const ind_order = req.body.data.ind_order;
|
2020-05-10 21:07:51 +02:00
|
|
|
|
const username = req.body.data.username;
|
2022-02-27 16:56:02 +01:00
|
|
|
|
const idapp = req.user.idapp;
|
2020-04-24 10:29:25 +02:00
|
|
|
|
const mydata = req.body.data;
|
|
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// const telegrambot = require('../telegram/telegrambot');
|
2020-07-11 17:10:19 +02:00
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
try {
|
2020-05-04 19:34:41 +02:00
|
|
|
|
let entra = false;
|
|
|
|
|
|
if (mydata.myfunc === shared_consts.CallFunz.AGGIUNGI_NUOVO_IMBARCO ||
|
2021-11-22 18:29:22 +01:00
|
|
|
|
mydata.myfunc === shared_consts.CallFunz.CANCELLA_IMBARCO) {
|
|
|
|
|
|
entra = true;
|
2020-05-04 19:34:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (!entra) {
|
|
|
|
|
|
// If I change my record...
|
2021-11-22 18:29:22 +01:00
|
|
|
|
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
2022-07-28 21:47:23 +02:00
|
|
|
|
!User.isFacilitatore(req.user.perm)) && (req.user._id.toString() !== id)) {
|
2020-05-04 19:34:41 +02:00
|
|
|
|
// If without permissions, exit
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.status(404).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
2020-05-04 19:34:41 +02:00
|
|
|
|
}
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let myuser = await User.findOne({idapp, username});
|
2020-04-24 10:29:25 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let fieldsvalue = {};
|
2020-05-04 19:34:41 +02:00
|
|
|
|
|
2022-02-03 00:33:15 +01:00
|
|
|
|
if (mydata.myfunc === shared_consts.CallFunz.ZOOM_GIA_PARTECIPATO) {
|
2020-09-04 00:06:49 +02:00
|
|
|
|
|
|
|
|
|
|
if (!!myuser.username) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let FormDaMostrare = telegrambot.getFormDaMostrare(idapp, mydata.myfunc,
|
|
|
|
|
|
myuser);
|
2020-09-04 00:06:49 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(idapp,
|
|
|
|
|
|
`L\'utente ${myuser.name} ${myuser.surname} (${myuser.username}) ha detto di aver già visto lo Zoom di Benvenuto`,
|
|
|
|
|
|
false, FormDaMostrare);
|
2020-09-04 00:06:49 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const ris = await User.findByIdAndUpdate(myuser.id,
|
|
|
|
|
|
{$set: {'profile.ask_zoom_partecipato': true}});
|
2020-09-04 00:06:49 +02:00
|
|
|
|
if (ris)
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
2020-09-04 00:06:49 +02:00
|
|
|
|
}
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
2020-05-19 00:18:13 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_ERR});
|
2020-05-19 00:18:13 +02:00
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
} catch (e) {
|
2020-05-04 19:34:41 +02:00
|
|
|
|
console.log(e.message);
|
2020-04-24 10:29:25 +02:00
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
|
router.get('/copyfromapptoapp/:idapporig/:idappdest', async (req, res) => {
|
2022-02-12 22:12:49 +01:00
|
|
|
|
// const idapporig = req.params.idapporig;
|
|
|
|
|
|
// const idappdest = req.params.idappdest;
|
|
|
|
|
|
// if (!idapporig || !idappdest)
|
|
|
|
|
|
// res.status(400).send();
|
|
|
|
|
|
//
|
|
|
|
|
|
// const mytablesstr = ['settings', 'users', 'templemail'];
|
|
|
|
|
|
//
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// let numrectot = 0;
|
|
|
|
|
|
// for (const table of mytablesstr) {
|
2022-02-16 19:21:12 +01:00
|
|
|
|
// const mytable = globalTables.getTableByTableName(table);
|
2022-02-12 22:12:49 +01:00
|
|
|
|
//
|
|
|
|
|
|
// tools.mylogshow('copyfromapptoapp: ', table, mytable);
|
|
|
|
|
|
//
|
|
|
|
|
|
// await mytable.DuplicateAllRecords(idapporig, idappdest).then((numrec) => {
|
|
|
|
|
|
// // tools.mylogshow(' REC TO MODIFY: ', rec);
|
|
|
|
|
|
// numrectot += numrec
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// res.send({ code: server_constants.RIS_CODE_OK, msg: '', numrectot });
|
|
|
|
|
|
//
|
|
|
|
|
|
// } catch (e) {
|
|
|
|
|
|
// tools.mylogserr('Error copyfromapptoapp: ', e);
|
|
|
|
|
|
// res.status(400).send();
|
|
|
|
|
|
// }
|
2020-01-13 23:52:51 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
|
2019-10-15 20:40:31 +02:00
|
|
|
|
const id = req.params.id;
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// const idapp = req.user.idapp;
|
2019-10-15 20:40:31 +02:00
|
|
|
|
const tablename = req.params.table;
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// let notifBot = false;
|
2019-10-15 20:40:31 +02:00
|
|
|
|
// const idapp = req.body.idapp;
|
|
|
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
|
console.log('id', id, 'table', tablename);
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const mytable = globalTables.getTableByTableName(tablename);
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const fields = {'ALL': 1};
|
2020-03-10 21:44:14 +01:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) &&
|
|
|
|
|
|
(tablename !== 'extralist') &&
|
|
|
|
|
|
!tools.ModificheConsentite(tablename, fields, id, req.user)) {
|
2019-10-15 20:40:31 +02:00
|
|
|
|
// If without permissions, exit
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.status(404).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
2019-10-15 20:40:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
let cancellato = false;
|
|
|
|
|
|
|
2022-02-03 00:33:15 +01:00
|
|
|
|
//++Tools: Notify...
|
|
|
|
|
|
tools.NotifyIfDelRecord(tablename);
|
2020-02-05 00:39:25 +01:00
|
|
|
|
|
2020-07-02 22:00:58 +02:00
|
|
|
|
if (!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
|
2020-04-24 10:29:25 +02:00
|
|
|
|
if (tablename === 'users') {
|
|
|
|
|
|
|
|
|
|
|
|
let fieldsvalue = {
|
2020-05-14 17:23:17 +02:00
|
|
|
|
deleted: true,
|
|
|
|
|
|
date_deleted: new Date(),
|
2020-04-24 10:29:25 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await mytable.findByIdAndUpdate(id, {$set: fieldsvalue});
|
2020-04-24 10:29:25 +02:00
|
|
|
|
|
|
|
|
|
|
cancellato = true;
|
2019-10-15 20:40:31 +02:00
|
|
|
|
}
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let ris = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (!cancellato) {
|
2022-03-04 15:30:11 +01:00
|
|
|
|
// ELIMINA VERAMENTE IL RECORD !!!
|
2020-04-24 10:29:25 +02:00
|
|
|
|
ris = await mytable.findByIdAndRemove(id).then((rec) => {
|
|
|
|
|
|
if (!rec) {
|
2021-01-18 00:48:17 +01:00
|
|
|
|
// res.status(404).send();
|
|
|
|
|
|
return false;
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-28 17:20:47 +01:00
|
|
|
|
if (tablename === shared_consts.TAB_MYGROUPS) {
|
|
|
|
|
|
// Se è un gruppo, allora cancella anche tutti i suoi riferimenti
|
|
|
|
|
|
User.removeAllUsersFromMyGroups(rec.idapp, rec.groupname);
|
2022-09-02 02:25:38 +02:00
|
|
|
|
} else if (tablename === shared_consts.TAB_MYCIRCUITS) {
|
|
|
|
|
|
// Se è un gruppo, allora cancella anche tutti i suoi riferimenti
|
|
|
|
|
|
User.removeAllUsersFromMyCircuits(rec.idapp, rec.name);
|
2022-02-28 17:20:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-04 15:30:11 +01:00
|
|
|
|
tools.refreshAllTablesInMem(rec.idapp, tablename, true, rec.username);
|
|
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
cancellato = true;
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
tools.mylog('DELETED ', rec._id);
|
|
|
|
|
|
|
2020-10-17 22:11:29 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}).catch((e) => {
|
2020-05-04 19:34:41 +02:00
|
|
|
|
console.log(e.message);
|
2020-04-24 10:29:25 +02:00
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
if (cancellato) {
|
2019-10-20 01:21:54 +02:00
|
|
|
|
// Do extra things after deleted
|
2021-01-18 00:48:17 +01:00
|
|
|
|
//let ris2 = await actions.doOtherlasThingsAfterDeleted(tablename, myrec, notifBot, req);
|
2020-09-04 00:06:49 +02:00
|
|
|
|
if (!!ris) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
2020-09-04 00:06:49 +02:00
|
|
|
|
}
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
2019-10-20 01:21:54 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
res.send({code: server_constants.RIS_CODE_ERR, msg: ''});
|
2020-04-24 10:29:25 +02:00
|
|
|
|
return ris;
|
2019-10-20 22:45:09 +02:00
|
|
|
|
|
2019-10-15 20:40:31 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
router.post('/duprec/:table/:id', authenticate, async (req, res) => {
|
2019-10-20 22:45:09 +02:00
|
|
|
|
const id = req.params.id;
|
|
|
|
|
|
const tablename = req.params.table;
|
|
|
|
|
|
// const idapp = req.body.idapp;
|
|
|
|
|
|
|
|
|
|
|
|
console.log('id', id, 'table', tablename);
|
|
|
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
|
const mytable = globalTables.getTableByTableName(tablename);
|
2019-10-20 22:45:09 +02:00
|
|
|
|
|
2020-01-03 22:02:18 +01:00
|
|
|
|
if (!req.user) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.status(404).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
2020-01-03 22:02:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
|
2019-10-20 22:45:09 +02:00
|
|
|
|
// If without permissions, exit
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.status(404).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
2019-10-20 22:45:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
return await mytable.findById(id).then(async (mydata) => {
|
2019-10-20 22:45:09 +02:00
|
|
|
|
|
2019-10-21 20:38:10 +02:00
|
|
|
|
const datadup = tools.CloneRecordToNew(mydata);
|
|
|
|
|
|
const mynewrec = new mytable(datadup);
|
2019-10-20 22:45:09 +02:00
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
return await mynewrec.save().then(async (rec) => {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
if (!rec) {
|
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
|
}
|
2019-10-20 22:45:09 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
tools.mylog('DUPLICATED ', rec);
|
2019-10-20 22:45:09 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
// Do extra things after deleted
|
2022-09-11 11:45:33 +02:00
|
|
|
|
return await actions.doOtherThingsAfterDuplicated(tablename, rec).
|
2021-11-22 18:29:22 +01:00
|
|
|
|
then(({myrec}) => {
|
|
|
|
|
|
// ...
|
|
|
|
|
|
mytable.findById(myrec._id).then((record) => {
|
|
|
|
|
|
return res.send(
|
|
|
|
|
|
{code: server_constants.RIS_CODE_OK, record, msg: ''});
|
|
|
|
|
|
});
|
2019-10-21 20:38:10 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
});
|
2019-10-21 20:38:10 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
}).catch((e) => {
|
|
|
|
|
|
console.error(e.message);
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2019-10-20 22:45:09 +02:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-05-10 01:50:40 +02:00
|
|
|
|
router.get('/loadsite/:userId/:idapp', authenticate_noerror, (req, res) => {
|
2021-06-04 10:07:57 +02:00
|
|
|
|
load(req, res, '0');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
router.get('/loadsite/:userId/:idapp/:vers', authenticate_noerror,
|
|
|
|
|
|
(req, res) => {
|
|
|
|
|
|
let versionstr = req.params.vers;
|
2021-10-05 00:20:12 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let version = tools.getVersionint(versionstr);
|
2021-06-04 10:07:57 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
load(req, res, version);
|
2022-07-27 20:56:01 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
});
|
2021-06-04 10:07:57 +02:00
|
|
|
|
|
|
|
|
|
|
function load(req, res, version) {
|
2019-10-23 23:47:21 +02:00
|
|
|
|
const userId = req.params.userId;
|
|
|
|
|
|
const idapp = req.params.idapp;
|
2021-06-04 10:07:57 +02:00
|
|
|
|
|
|
|
|
|
|
if (!version) {
|
|
|
|
|
|
version = '0';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-23 14:13:40 +01:00
|
|
|
|
let gestoredelSito = '0';
|
2021-06-04 10:07:57 +02:00
|
|
|
|
if (!!req.user) {
|
2022-02-03 00:33:15 +01:00
|
|
|
|
gestoredelSito = (User.isAdmin(req.user.perm) ||
|
|
|
|
|
|
User.isManager(req.user.perm) ||
|
2021-11-22 18:29:22 +01:00
|
|
|
|
User.isEditor(req.user.perm)) ? '1' : '0';
|
2021-06-04 10:07:57 +02:00
|
|
|
|
}
|
2021-02-18 12:19:35 +01:00
|
|
|
|
|
2019-10-23 23:47:21 +02:00
|
|
|
|
// var category = req.params.category;
|
|
|
|
|
|
|
2019-10-24 23:30:45 +02:00
|
|
|
|
// tools.mylog('loadsite : ', req.params);
|
2019-10-23 23:47:21 +02:00
|
|
|
|
|
|
|
|
|
|
let bookedevent = [];
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// let msgs = [];
|
|
|
|
|
|
|
2021-02-24 04:48:31 +01:00
|
|
|
|
let socioresidente = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (!!req.user)
|
|
|
|
|
|
socioresidente = req.user.profile.socioresidente;
|
2019-10-23 23:47:21 +02:00
|
|
|
|
|
|
|
|
|
|
if (userId !== '0') {
|
|
|
|
|
|
// LOGGED WITH USERID
|
2022-02-03 00:33:15 +01:00
|
|
|
|
bookedevent = Booking.findAllByUserIdAndIdApp(userId, idapp,
|
|
|
|
|
|
gestoredelSito);
|
2019-10-23 23:47:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Extract all the todos of the userId only
|
2021-02-18 12:19:35 +01:00
|
|
|
|
const eventlist = MyEvent.findAllIdApp(socioresidente, idapp);
|
2019-10-23 23:47:21 +02:00
|
|
|
|
const operators = Operator.findAllIdApp(idapp);
|
2021-06-04 10:07:57 +02:00
|
|
|
|
const internalpages = MyPage.findInternalPages(idapp);
|
2019-10-23 23:47:21 +02:00
|
|
|
|
const wheres = Where.findAllIdApp(idapp);
|
|
|
|
|
|
const contribtype = Contribtype.findAllIdApp(idapp);
|
2020-01-03 01:52:49 +01:00
|
|
|
|
const paymenttype = PaymentType.findAllIdApp(idapp);
|
2019-11-12 21:34:03 +01:00
|
|
|
|
const disciplines = Discipline.findAllIdApp(idapp);
|
2022-10-27 11:22:58 +02:00
|
|
|
|
const myelems = MyElem.findAllIdApp(idapp);
|
2021-12-23 14:13:40 +01:00
|
|
|
|
const settings = Settings.findAllIdApp(idapp, false, false);
|
2019-12-04 02:03:44 +01:00
|
|
|
|
|
2019-10-28 16:01:28 +01:00
|
|
|
|
const permissions = Permission.findAllIdApp();
|
2019-10-23 23:47:21 +02:00
|
|
|
|
|
2019-11-21 00:18:40 +01:00
|
|
|
|
let newstosent = Promise.resolve([]);
|
|
|
|
|
|
let mailinglist = Promise.resolve([]);
|
2021-06-04 10:07:57 +02:00
|
|
|
|
let mypage;
|
|
|
|
|
|
if (version > 91)
|
|
|
|
|
|
mypage = MyPage.findOnlyStruttRec(idapp);
|
|
|
|
|
|
else
|
|
|
|
|
|
mypage = MyPage.findAllIdApp(idapp);
|
2020-01-21 01:37:15 +01:00
|
|
|
|
let calzoom = CalZoom.findAllIdApp(idapp);
|
2021-12-23 14:13:40 +01:00
|
|
|
|
|
|
|
|
|
|
let gallery = Promise.resolve([]);
|
|
|
|
|
|
if (gestoredelSito) {
|
|
|
|
|
|
gallery = Gallery.findAllIdApp(idapp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-25 03:54:16 +01:00
|
|
|
|
let producers = Producer.findAllIdApp(idapp);
|
2021-02-03 01:33:30 +01:00
|
|
|
|
let groups = Group.findAllIdApp(idapp);
|
2021-12-23 14:13:40 +01:00
|
|
|
|
|
|
|
|
|
|
// ....
|
2021-02-11 02:20:35 +01:00
|
|
|
|
let resps = User.getusersRespList(idapp);
|
|
|
|
|
|
let workers = User.getusersWorkersList(idapp);
|
2020-12-25 03:54:16 +01:00
|
|
|
|
let storehouses = Storehouse.findAllIdApp(idapp);
|
2021-02-03 01:33:30 +01:00
|
|
|
|
let departments = Department.findAllIdApp(idapp);
|
2021-12-23 14:13:40 +01:00
|
|
|
|
|
|
|
|
|
|
// SKILLS:
|
2021-10-05 00:20:12 +02:00
|
|
|
|
let levels = Level.findAllIdApp(idapp);
|
2022-02-12 02:20:07 +01:00
|
|
|
|
let adtypes = AdType.findAllIdApp(idapp);
|
2022-02-21 13:12:27 +01:00
|
|
|
|
let adtypegoods = AdTypeGood.findAllIdApp(idapp);
|
2021-10-05 00:20:12 +02:00
|
|
|
|
let skills = Skill.findAllIdApp(idapp);
|
2022-02-21 13:12:27 +01:00
|
|
|
|
let goods = Good.findAllIdApp(idapp);
|
|
|
|
|
|
//let subSkills = SubSkill.findAllIdApp(idapp);
|
2021-10-08 00:38:35 +02:00
|
|
|
|
let statusSkills = StatusSkill.findAllIdApp(idapp);
|
2021-10-05 00:20:12 +02:00
|
|
|
|
let sectors = Sector.findAllIdApp(idapp);
|
2022-02-21 13:12:27 +01:00
|
|
|
|
let sectorgoods = SectorGood.findAllIdApp(idapp);
|
2022-02-05 23:28:15 +01:00
|
|
|
|
let catgrps = CatGrp.findAllIdApp(idapp);
|
2022-05-05 00:38:41 +02:00
|
|
|
|
let site = Site.findAllIdApp(idapp);
|
2022-06-16 20:34:42 +02:00
|
|
|
|
let mygroups = MyGroup.findAllGroups(idapp);
|
2022-09-03 13:06:58 +02:00
|
|
|
|
let listcircuits = Circuit.findAllIdApp(idapp);
|
2022-03-09 14:53:09 +01:00
|
|
|
|
// let cities = City.findAllIdApp(idapp);
|
|
|
|
|
|
let provinces = Province.findAllIdApp(idapp);
|
2020-12-25 03:54:16 +01:00
|
|
|
|
let cart = null;
|
2021-01-18 00:48:17 +01:00
|
|
|
|
let orderscart = null;
|
2021-12-23 14:13:40 +01:00
|
|
|
|
if (gestoredelSito) {
|
2019-11-21 00:18:40 +01:00
|
|
|
|
newstosent = Newstosent.findAllIdApp(idapp);
|
|
|
|
|
|
}
|
2019-10-27 00:37:10 +02:00
|
|
|
|
|
2020-01-20 01:48:25 +01:00
|
|
|
|
let calcstat = null;
|
2020-12-25 03:54:16 +01:00
|
|
|
|
if (req.user) {
|
2020-01-20 01:48:25 +01:00
|
|
|
|
calcstat = User.calculateStat(idapp, req.user.username);
|
2020-12-25 03:54:16 +01:00
|
|
|
|
cart = Cart.getCartByUserId(req.user.id, idapp);
|
2021-04-30 01:31:12 +02:00
|
|
|
|
if (User.isManager(req.user.perm)) {
|
|
|
|
|
|
// Prende Tutti gli Ordini !
|
2021-11-22 18:29:22 +01:00
|
|
|
|
orderscart = OrdersCart.getOrdersCartByUserId('ALL', idapp, 0);
|
2021-04-30 01:31:12 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
orderscart = OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0);
|
|
|
|
|
|
}
|
2020-12-25 03:54:16 +01:00
|
|
|
|
}
|
2022-02-03 00:33:15 +01:00
|
|
|
|
let askedfriends = [];
|
2022-01-20 00:39:06 +01:00
|
|
|
|
let myuserextra = null;
|
2022-01-14 23:54:33 +01:00
|
|
|
|
if (req.user) {
|
|
|
|
|
|
// askedfriends = User.getAskedFriendsByUsername(idapp, req.user.username);
|
2022-09-14 11:32:04 +02:00
|
|
|
|
myuserextra = User.addExtraInfo(idapp, req.user);
|
2022-01-14 23:54:33 +01:00
|
|
|
|
}
|
2020-01-20 01:48:25 +01:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return Promise.all([
|
|
|
|
|
|
bookedevent,
|
|
|
|
|
|
eventlist,
|
|
|
|
|
|
operators,
|
|
|
|
|
|
wheres,
|
|
|
|
|
|
contribtype,
|
|
|
|
|
|
settings,
|
|
|
|
|
|
permissions,
|
|
|
|
|
|
disciplines,
|
|
|
|
|
|
newstosent,
|
|
|
|
|
|
mailinglist,
|
|
|
|
|
|
mypage,
|
|
|
|
|
|
gallery,
|
|
|
|
|
|
paymenttype,
|
|
|
|
|
|
calcstat,
|
|
|
|
|
|
calzoom,
|
|
|
|
|
|
producers,
|
|
|
|
|
|
cart,
|
|
|
|
|
|
storehouses,
|
|
|
|
|
|
departments,
|
|
|
|
|
|
orderscart,
|
|
|
|
|
|
groups,
|
|
|
|
|
|
resps,
|
|
|
|
|
|
workers,
|
|
|
|
|
|
internalpages,
|
|
|
|
|
|
levels,
|
2022-03-10 00:28:23 +01:00
|
|
|
|
skills, //25
|
2022-02-21 13:12:27 +01:00
|
|
|
|
//subSkills,
|
2022-03-10 00:28:23 +01:00
|
|
|
|
myuserextra, // 26
|
|
|
|
|
|
sectors, // 27
|
|
|
|
|
|
statusSkills, //28
|
2022-03-09 14:53:09 +01:00
|
|
|
|
// cities,
|
|
|
|
|
|
provinces,
|
2022-02-05 23:28:15 +01:00
|
|
|
|
catgrps,
|
2022-02-12 02:20:07 +01:00
|
|
|
|
adtypes,
|
2022-02-21 13:12:27 +01:00
|
|
|
|
adtypegoods,
|
|
|
|
|
|
sectorgoods,
|
|
|
|
|
|
goods,
|
2022-05-05 00:38:41 +02:00
|
|
|
|
site,
|
2022-06-16 20:34:42 +02:00
|
|
|
|
mygroups,
|
2022-09-03 13:06:58 +02:00
|
|
|
|
listcircuits, // 37
|
2022-10-27 11:22:58 +02:00
|
|
|
|
myelems, // 38
|
2022-02-16 09:40:16 +01:00
|
|
|
|
]).then((arrdata) => {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
// console.table(arrdata);
|
2022-01-20 00:39:06 +01:00
|
|
|
|
let myuser = req.user;
|
2021-11-22 18:29:22 +01:00
|
|
|
|
if (myuser) {
|
2022-01-14 23:54:33 +01:00
|
|
|
|
try {
|
2022-02-21 13:12:27 +01:00
|
|
|
|
myuser = arrdata[26];
|
2022-01-20 00:39:06 +01:00
|
|
|
|
if (myuser) {
|
|
|
|
|
|
myuser.password = '';
|
2022-03-06 00:48:33 +01:00
|
|
|
|
myuser.calcstat = arrdata[13];
|
2022-01-20 00:39:06 +01:00
|
|
|
|
}
|
2022-01-14 23:54:33 +01:00
|
|
|
|
} catch (e) {}
|
2021-11-22 18:29:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
if (version < 91) {
|
|
|
|
|
|
res.send({
|
|
|
|
|
|
bookedevent: arrdata[0],
|
|
|
|
|
|
eventlist: arrdata[1],
|
|
|
|
|
|
operators: arrdata[2],
|
|
|
|
|
|
wheres: arrdata[3],
|
|
|
|
|
|
contribtype: arrdata[4],
|
|
|
|
|
|
settings: arrdata[5],
|
|
|
|
|
|
permissions: arrdata[6],
|
|
|
|
|
|
disciplines: arrdata[7],
|
|
|
|
|
|
newstosent: arrdata[8],
|
|
|
|
|
|
mailinglist: arrdata[9],
|
|
|
|
|
|
mypage: arrdata[10],
|
|
|
|
|
|
gallery: arrdata[11],
|
|
|
|
|
|
paymenttypes: arrdata[12],
|
|
|
|
|
|
calzoom: arrdata[14],
|
|
|
|
|
|
producers: arrdata[15],
|
|
|
|
|
|
cart: arrdata[16],
|
|
|
|
|
|
storehouses: arrdata[17],
|
|
|
|
|
|
departments: arrdata[18],
|
|
|
|
|
|
orders: arrdata[19],
|
|
|
|
|
|
groups: arrdata[20],
|
|
|
|
|
|
resps: arrdata[21],
|
|
|
|
|
|
workers: arrdata[22],
|
|
|
|
|
|
myuser,
|
|
|
|
|
|
internalpages: arrdata[23],
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
res.send({
|
|
|
|
|
|
bookedevent: arrdata[0],
|
|
|
|
|
|
eventlist: arrdata[1],
|
|
|
|
|
|
operators: arrdata[2],
|
|
|
|
|
|
wheres: arrdata[3],
|
|
|
|
|
|
contribtype: arrdata[4],
|
|
|
|
|
|
settings: arrdata[5],
|
|
|
|
|
|
permissions: arrdata[6],
|
|
|
|
|
|
disciplines: arrdata[7],
|
|
|
|
|
|
newstosent: arrdata[8],
|
|
|
|
|
|
mailinglist: arrdata[9],
|
|
|
|
|
|
mypage: arrdata[10],
|
|
|
|
|
|
gallery: arrdata[11],
|
|
|
|
|
|
paymenttypes: arrdata[12],
|
|
|
|
|
|
calzoom: arrdata[14],
|
|
|
|
|
|
producers: arrdata[15],
|
|
|
|
|
|
cart: arrdata[16],
|
|
|
|
|
|
storehouses: arrdata[17],
|
|
|
|
|
|
departments: arrdata[18],
|
|
|
|
|
|
orders: arrdata[19],
|
|
|
|
|
|
groups: arrdata[20],
|
|
|
|
|
|
resps: arrdata[21],
|
|
|
|
|
|
workers: arrdata[22],
|
|
|
|
|
|
myuser,
|
|
|
|
|
|
internalpages: arrdata[23],
|
|
|
|
|
|
levels: arrdata[24],
|
|
|
|
|
|
skills: arrdata[25],
|
2022-02-21 13:12:27 +01:00
|
|
|
|
// subSkills: arrdata[26],
|
|
|
|
|
|
// myuser arrdata[26]
|
2021-12-31 01:44:28 +01:00
|
|
|
|
sectors: arrdata[27],
|
|
|
|
|
|
statusSkills: arrdata[28],
|
2022-03-09 14:53:09 +01:00
|
|
|
|
provinces: arrdata[29],
|
2022-02-21 13:12:27 +01:00
|
|
|
|
catgrps: arrdata[30],
|
|
|
|
|
|
adtypes: arrdata[31],
|
|
|
|
|
|
adtypegoods: arrdata[32],
|
|
|
|
|
|
sectorgoods: arrdata[33],
|
|
|
|
|
|
goods: arrdata[34],
|
2022-05-05 00:38:41 +02:00
|
|
|
|
site: arrdata[35],
|
2022-06-16 20:34:42 +02:00
|
|
|
|
mygroups: arrdata[36],
|
2022-09-03 13:06:58 +02:00
|
|
|
|
listcircuits: arrdata[37],
|
2022-10-27 11:22:58 +02:00
|
|
|
|
myelems: arrdata[38],
|
2021-11-22 18:29:22 +01:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2020-01-20 01:48:25 +01:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
}).catch((e) => {
|
|
|
|
|
|
console.log(e.message);
|
|
|
|
|
|
res.status(400).send(e);
|
|
|
|
|
|
});
|
2019-10-23 23:47:21 +02:00
|
|
|
|
|
2021-06-04 10:07:57 +02:00
|
|
|
|
}
|
2019-10-23 23:47:21 +02:00
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
router.get(process.env.LINK_CHECK_UPDATES, authenticate, async (req, res) => {
|
2019-10-24 23:30:45 +02:00
|
|
|
|
const userId = req.user._id;
|
2020-04-24 10:29:25 +02:00
|
|
|
|
const idapp = req.query.idapp;
|
2019-10-24 23:30:45 +02:00
|
|
|
|
|
|
|
|
|
|
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
|
|
|
|
|
|
|
|
|
|
|
|
if (!ObjectID.isValid(userId)) {
|
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-14 00:31:53 +02:00
|
|
|
|
await CfgServer.find({idapp}).then((arrcfgrec) => {
|
2019-10-24 23:30:45 +02:00
|
|
|
|
|
|
|
|
|
|
if (!arrcfgrec)
|
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
|
|
2022-09-02 02:25:38 +02:00
|
|
|
|
// ++Add to Log Stat ....
|
2019-10-24 23:30:45 +02:00
|
|
|
|
|
|
|
|
|
|
// const sall = '0';
|
|
|
|
|
|
|
2019-10-25 19:08:38 +02:00
|
|
|
|
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
|
2022-07-10 01:25:19 +02:00
|
|
|
|
let last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, idapp);
|
2022-08-09 17:32:06 +02:00
|
|
|
|
let last_notifs = SendNotif.findLastNotifsByUserIdAndIdApp(req.user.username, idapp, 40);
|
2019-10-25 19:08:38 +02:00
|
|
|
|
|
2019-10-24 23:30:45 +02:00
|
|
|
|
let usersList = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (req.user) {
|
|
|
|
|
|
// If User is Admin, then send user Lists
|
2021-11-22 18:29:22 +01:00
|
|
|
|
if (User.isAdmin(req.user.perm) || User.isEditor(req.user.perm) ||
|
|
|
|
|
|
User.isManager(req.user.perm)) {
|
2021-12-23 14:13:40 +01:00
|
|
|
|
|
2019-10-24 23:30:45 +02:00
|
|
|
|
// Send UsersList
|
2022-02-27 16:56:02 +01:00
|
|
|
|
usersList = User.getUsersList(idapp);
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// usersList = null;
|
2019-10-24 23:30:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-10 01:25:19 +02:00
|
|
|
|
return Promise.all([usersList, last_msgs, last_notifs]).then((arrdata) => {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
// console.table(arrdata);
|
|
|
|
|
|
return res.send({
|
2022-05-14 00:31:53 +02:00
|
|
|
|
CfgServer: arrcfgrec,
|
2021-11-22 18:29:22 +01:00
|
|
|
|
usersList: arrdata[0],
|
|
|
|
|
|
last_msgs: arrdata[1],
|
2022-07-10 01:25:19 +02:00
|
|
|
|
last_notifs: arrdata[2],
|
2019-10-24 23:30:45 +02:00
|
|
|
|
});
|
2021-11-22 18:29:22 +01:00
|
|
|
|
});
|
2019-10-24 23:30:45 +02:00
|
|
|
|
|
|
|
|
|
|
}).catch((e) => {
|
2020-05-04 19:34:41 +02:00
|
|
|
|
console.log(e.message);
|
2021-11-22 18:29:22 +01:00
|
|
|
|
res.status(400).send({code: server_constants.RIS_CODE_ERR, msg: e});
|
2019-10-24 23:30:45 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2019-12-27 12:41:39 +01:00
|
|
|
|
router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// const dir = req.params.dir;
|
|
|
|
|
|
// const idapp = req.user.idapp;
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
/*
|
|
|
|
|
|
const form = new formidable.IncomingForm();
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
form.parse(req);
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
const client = new ftp(process.env.FTPSERVER_HOST, process.env.FTPSERVER_PORT, process.env.FTPSERVER_USER + idapp + '@associazioneshen.it', process.env.FTPSERVER_PWD + idapp, false, 134217728);
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
// SSL_OP_NO_TLSv1_2 = 134217728
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
// console.log('client', client);
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
form.uploadDir = folder + '/' + dir;
|
|
|
|
|
|
try {
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
form.on('fileBegin', async function (name, file){
|
|
|
|
|
|
file.path = folder + '/' + file.name;
|
|
|
|
|
|
});
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
form.on('file', async function (name, file){
|
|
|
|
|
|
try {
|
|
|
|
|
|
// Create directory remote
|
|
|
|
|
|
|
|
|
|
|
|
if (!!dir)
|
|
|
|
|
|
await client.createDir(dir);
|
|
|
|
|
|
|
2020-02-05 00:39:25 +01:00
|
|
|
|
const miofile = (dir) ? dir + ` / ` + file.name : file.name;
|
2019-12-28 14:30:30 +01:00
|
|
|
|
console.log('Upload...');
|
|
|
|
|
|
const ret = await client.upload(file.path, miofile, 755);
|
|
|
|
|
|
console.log('Uploaded ' + file.name, 'status:', ret);
|
|
|
|
|
|
if (!ret)
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
else {
|
|
|
|
|
|
// Delete file from local directory
|
|
|
|
|
|
fs.unlinkSync(file.path);
|
|
|
|
|
|
res.end();
|
|
|
|
|
|
}
|
|
|
|
|
|
}catch (e) {
|
|
|
|
|
|
console.log('error', e);
|
2019-12-07 00:20:06 +01:00
|
|
|
|
res.status(400).send();
|
2019-12-27 12:41:39 +01:00
|
|
|
|
}
|
2019-12-28 14:30:30 +01:00
|
|
|
|
});
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
form.on('aborted', () => {
|
|
|
|
|
|
console.error('Request aborted by the user');
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
form.on('error', (err) => {
|
|
|
|
|
|
console.error('Error Uploading', err);
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log('Error', e)
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
2019-12-27 12:41:39 +01:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-10-05 00:20:12 +02:00
|
|
|
|
function uploadFile(req, res, version) {
|
|
|
|
|
|
// console.log('/upload dir:' + dir);
|
2021-10-28 00:38:10 +02:00
|
|
|
|
const dir = tools.invertescapeslash(req.params.dir);
|
2022-09-19 19:40:30 +02:00
|
|
|
|
console.log('inverted = ', dir);
|
2022-02-28 17:20:47 +01:00
|
|
|
|
const idapp = req.user.idapp;
|
2019-12-27 12:41:39 +01:00
|
|
|
|
|
|
|
|
|
|
const form = new formidable.IncomingForm();
|
|
|
|
|
|
|
|
|
|
|
|
form.parse(req);
|
|
|
|
|
|
|
2021-10-05 00:20:12 +02:00
|
|
|
|
let dirmain = '/statics';
|
|
|
|
|
|
if (version > 0) {
|
2022-02-09 19:48:39 +01:00
|
|
|
|
if (tools.sulServer()) {
|
2021-10-28 00:38:10 +02:00
|
|
|
|
dirmain = '';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
dirmain = '/public';
|
|
|
|
|
|
}
|
2021-10-05 00:20:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-19 19:40:30 +02:00
|
|
|
|
const mydir2 = folder + '/' + dir;
|
|
|
|
|
|
tools.mkdirpath(mydir2);
|
|
|
|
|
|
form.uploadDir = mydir2;
|
2019-12-27 12:41:39 +01:00
|
|
|
|
try {
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
form.on('fileBegin', async function(name, file) {
|
2022-09-19 19:40:30 +02:00
|
|
|
|
const mydir = folder + '/' + file.newFilename;
|
|
|
|
|
|
// tools.mkdirpath(mydir);
|
|
|
|
|
|
file.path = mydir
|
2019-12-27 12:41:39 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
form.on('file', async function(name, file) {
|
2019-12-27 12:41:39 +01:00
|
|
|
|
try {
|
2022-09-11 11:45:33 +02:00
|
|
|
|
console.log('1) Uploading ' + file.originalFilename);
|
2022-02-03 00:33:15 +01:00
|
|
|
|
const mydir = tools.getdirByIdApp(idapp) + dirmain +
|
|
|
|
|
|
server_constants.DIR_UPLOAD + '/' + dir;
|
2019-12-28 14:30:30 +01:00
|
|
|
|
|
2022-09-19 19:40:30 +02:00
|
|
|
|
// console.log('mydir', mydir);
|
|
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
// Create Dir if doesn't exist:
|
2022-02-21 18:14:56 +01:00
|
|
|
|
const rismk = tools.mkdirpath(mydir);
|
2022-01-23 23:25:34 +01:00
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
let filename = file.originalFilename;
|
2022-01-23 23:25:34 +01:00
|
|
|
|
let ext = path.extname(filename);
|
|
|
|
|
|
|
|
|
|
|
|
//++Todo: Modifica del nomefile... da passare al frontend
|
|
|
|
|
|
//if (mydir.includes('profile')) {
|
|
|
|
|
|
// filename = uuidv4() + ext;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
2022-02-03 00:33:15 +01:00
|
|
|
|
file.name = filename;
|
2022-01-23 23:25:34 +01:00
|
|
|
|
let resized_img = mydir + '/' + server_constants.PREFIX_IMG + filename;
|
2019-12-28 14:30:30 +01:00
|
|
|
|
|
2022-09-11 11:45:33 +02:00
|
|
|
|
oldpath = file.newFilename;
|
2022-09-19 19:40:30 +02:00
|
|
|
|
|
|
|
|
|
|
let fromfile = '.'+server_constants.DIR_UPLOAD + '/' + dir + '/' + oldpath;
|
|
|
|
|
|
let tofile = '.'+server_constants.DIR_UPLOAD + '/' + dir + '/' +file.originalFilename;
|
|
|
|
|
|
let mydircurrent = process.cwd() + '/src/server/router/upload/' + dir;
|
|
|
|
|
|
fromfile = mydircurrent + '/' + oldpath;
|
|
|
|
|
|
tofile = mydir + '/' + file.originalFilename;
|
|
|
|
|
|
let newname = tofile;
|
2022-01-23 23:25:34 +01:00
|
|
|
|
file.path = newname;
|
2022-09-19 19:40:30 +02:00
|
|
|
|
// console.log('fromfile', fromfile)
|
|
|
|
|
|
// console.log('tofile', tofile);
|
2019-12-27 12:41:39 +01:00
|
|
|
|
|
2022-03-30 22:51:03 +02:00
|
|
|
|
if (!tools.sulServer()) {
|
|
|
|
|
|
res.end();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
// Move in the folder application !
|
2022-09-19 19:40:30 +02:00
|
|
|
|
tools.move(fromfile, tofile, (err) => {
|
2022-02-28 17:20:47 +01:00
|
|
|
|
if (err) {
|
2022-03-01 23:50:58 +01:00
|
|
|
|
console.log('err uploadDir:', err);
|
2022-02-28 17:20:47 +01:00
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
} else {
|
2021-12-21 18:12:28 +01:00
|
|
|
|
|
2022-02-28 17:20:47 +01:00
|
|
|
|
// Salva le immagini in formato compresso
|
|
|
|
|
|
try {
|
|
|
|
|
|
let resized_img_small = tools.extractFilePath(newname) + '/' +
|
|
|
|
|
|
server_constants.PREFIX_IMG_SMALL +
|
|
|
|
|
|
tools.extractFileName(newname);
|
|
|
|
|
|
// SMALL
|
2022-03-01 23:50:58 +01:00
|
|
|
|
|
|
|
|
|
|
// questa opzione 'failOnError' serve per risolvere l'errore (Error: VipsJpeg: Invalid SOS parameters for sequential JPEG
|
2022-07-10 01:25:19 +02:00
|
|
|
|
sharp(newname, {failOnError: false}).
|
2022-02-28 17:20:47 +01:00
|
|
|
|
resize(64, 64).
|
2022-03-01 23:50:58 +01:00
|
|
|
|
withMetadata().
|
2022-02-28 17:20:47 +01:00
|
|
|
|
toFile(resized_img_small);
|
|
|
|
|
|
|
|
|
|
|
|
// MEDIUM
|
2022-03-01 23:50:58 +01:00
|
|
|
|
let resized_img = tools.extractFilePath(newname) + '/' + server_constants.PREFIX_IMG + tools.extractFileName(newname);
|
2022-07-10 01:25:19 +02:00
|
|
|
|
sharp(newname, {failOnError: false}).
|
|
|
|
|
|
resize({
|
2022-03-01 23:50:58 +01:00
|
|
|
|
width: 512,
|
2022-07-27 20:56:01 +02:00
|
|
|
|
// height: 512,
|
|
|
|
|
|
//fit: sharp.fit.cover,
|
|
|
|
|
|
fit: sharp.fit.contain,
|
|
|
|
|
|
// position: sharp.strategy.entropy,
|
2022-07-10 01:25:19 +02:00
|
|
|
|
}).withMetadata().toFile(resized_img, function(err) {
|
|
|
|
|
|
|
|
|
|
|
|
// console.log('3) Ridimensionata Immagine ' + newname, 'in', resized_img);
|
2022-02-16 19:21:12 +01:00
|
|
|
|
|
2022-07-10 01:25:19 +02:00
|
|
|
|
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) => {
|
2022-02-28 17:20:47 +01:00
|
|
|
|
if (err)
|
2022-07-10 01:25:19 +02:00
|
|
|
|
console.error('err', err);
|
|
|
|
|
|
else
|
|
|
|
|
|
console.log('move', newname);
|
2022-02-28 17:20:47 +01:00
|
|
|
|
});
|
2022-07-10 01:25:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
console.error('Error Upload: ', err);
|
|
|
|
|
|
});
|
2022-02-28 17:20:47 +01:00
|
|
|
|
} catch (e) {
|
2022-03-01 23:50:58 +01:00
|
|
|
|
console.error('Error Upload(2) ', e);
|
2022-02-28 17:20:47 +01:00
|
|
|
|
}
|
2022-02-16 09:40:16 +01:00
|
|
|
|
}
|
2021-12-21 18:12:28 +01:00
|
|
|
|
|
2022-01-26 01:31:22 +01:00
|
|
|
|
res.end();
|
2022-03-01 23:50:58 +01:00
|
|
|
|
// console.log('res.end');
|
2022-01-23 23:25:34 +01:00
|
|
|
|
// return res.send({filename: newname });
|
2021-12-21 18:12:28 +01:00
|
|
|
|
|
2019-12-27 12:41:39 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
} catch (e) {
|
2019-12-27 12:41:39 +01:00
|
|
|
|
console.log('error', e);
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2022-01-23 23:25:34 +01:00
|
|
|
|
form.on('end', function() {
|
2022-09-19 19:40:30 +02:00
|
|
|
|
console.log('-> upload done');
|
2022-01-23 23:25:34 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2019-12-27 12:41:39 +01:00
|
|
|
|
form.on('aborted', () => {
|
|
|
|
|
|
console.error('Request aborted by the user');
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
form.on('error', (err) => {
|
|
|
|
|
|
console.error('Error Uploading', err);
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
console.log('Error', e);
|
2019-12-27 12:41:39 +01:00
|
|
|
|
}
|
2021-10-05 00:20:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
router.post('/upload/:dir', authenticate, (req, res) => {
|
2022-01-23 23:25:34 +01:00
|
|
|
|
return uploadFile(req, res, 0);
|
2021-10-05 00:20:12 +02:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-10-28 00:38:10 +02:00
|
|
|
|
router.post('/uploadnew/:vers/:dir/', authenticate, (req, res) => {
|
2021-10-05 00:20:12 +02:00
|
|
|
|
let versionstr = req.params.vers;
|
|
|
|
|
|
let version = tools.getVersionint(versionstr);
|
|
|
|
|
|
|
2021-12-21 18:12:28 +01:00
|
|
|
|
try {
|
2022-01-23 23:25:34 +01:00
|
|
|
|
return uploadFile(req, res, version);
|
2021-12-21 18:12:28 +01:00
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log('error', e);
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
}
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
router.delete('/delfile/:vers', authenticate, (req, res) => {
|
|
|
|
|
|
let versionstr = req.params.vers;
|
|
|
|
|
|
let version = tools.getVersionint(versionstr);
|
|
|
|
|
|
deleteFile(req, res, version);
|
|
|
|
|
|
});
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2019-12-28 02:16:29 +01:00
|
|
|
|
router.delete('/delfile', authenticate, (req, res) => {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
deleteFile(req, res, 0);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function deleteFile(req, res, version) {
|
2019-12-28 02:16:29 +01:00
|
|
|
|
const relativefile = req.query.filename;
|
|
|
|
|
|
const idapp = req.user.idapp;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let dirmain = '';
|
|
|
|
|
|
if (version > 0) {
|
2022-02-09 19:48:39 +01:00
|
|
|
|
if (tools.sulServer() !== 1) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
dirmain = '/public';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-12-28 02:16:29 +01:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
console.log('Delete file ' + relativefile);
|
|
|
|
|
|
// ++ Move in the folder application !
|
2021-12-03 22:48:05 +01:00
|
|
|
|
let fullpathfile = tools.getdirByIdApp(idapp) + dirmain + '/' +
|
|
|
|
|
|
relativefile;
|
2019-12-28 02:16:29 +01:00
|
|
|
|
|
2021-12-21 18:12:28 +01:00
|
|
|
|
tools.delete(fullpathfile, true, (err) => {
|
2019-12-28 02:16:29 +01:00
|
|
|
|
if (err) console.log('err', err);
|
|
|
|
|
|
if (err === undefined || err.errno === -2)
|
2021-11-22 18:29:22 +01:00
|
|
|
|
res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
2019-12-28 02:16:29 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
} catch (e) {
|
2019-12-28 02:16:29 +01:00
|
|
|
|
console.log('error', e);
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
console.log('Error', e);
|
2019-12-28 02:16:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
}
|
2019-12-28 02:16:29 +01:00
|
|
|
|
|
2019-02-05 03:40:22 +01:00
|
|
|
|
module.exports = router;
|