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-20 01:48:25 +01:00
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
|
|
|
2020-01-30 01:19:25 +01:00
|
|
|
|
const telegrambot = require('../telegram/telegrambot');
|
|
|
|
|
|
|
2020-01-20 01:48:25 +01:00
|
|
|
|
const sendemail = require('../sendemail');
|
2019-02-05 03:40:22 +01:00
|
|
|
|
|
2021-12-21 18:12:28 +01:00
|
|
|
|
const resizer = require('node-image-resizer');
|
|
|
|
|
|
|
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');
|
|
|
|
|
|
const {ListaIngresso} = require('../models/listaingresso');
|
|
|
|
|
|
const {Graduatoria} = require('../models/graduatoria');
|
2019-02-22 10:23:39 +01:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const mongoose = require('mongoose').set('debug', false);
|
2019-02-22 10:23:39 +01:00
|
|
|
|
const cfgserver = mongoose.model('cfgserver');
|
|
|
|
|
|
|
2022-01-23 23:25:34 +01:00
|
|
|
|
const uuidv4 = require('uuid/v4'); // I chose v4 ‒ you can select others
|
|
|
|
|
|
|
2019-12-07 00:20:06 +01:00
|
|
|
|
const ftp = require('../ftp/FTPClient'),
|
2021-11-22 18:29:22 +01:00
|
|
|
|
formidable = require('formidable'),
|
|
|
|
|
|
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');
|
|
|
|
|
|
const {Nave} = require('../models/nave');
|
|
|
|
|
|
const {Flotta} = require('../models/flotta');
|
|
|
|
|
|
const {NavePersistente} = require('../models/navepersistente');
|
2020-05-10 21:07:51 +02:00
|
|
|
|
// const { ExtraList } = require('../models/extralist');
|
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');
|
|
|
|
|
|
const {Skill} = require('../models/skill');
|
2021-12-31 01:44:28 +01:00
|
|
|
|
const {SubSkill} = require('../models/subskill');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {MySkill} = require('../models/myskill');
|
|
|
|
|
|
const {StatusSkill} = require('../models/statusSkill');
|
|
|
|
|
|
const {City} = require('../models/city');
|
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');
|
|
|
|
|
|
const {Level} = require('../models/level');
|
2021-12-21 01:27:45 +01:00
|
|
|
|
const Pickup = require('../models/pickup');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {Newstosent} = require('../models/newstosent');
|
|
|
|
|
|
const {MyPage} = require('../models/mypage');
|
2021-12-29 18:26:08 +01:00
|
|
|
|
const {MyBot} = require('../models/bot');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {CalZoom} = require('../models/calzoom');
|
|
|
|
|
|
const {Gallery} = require('../models/gallery');
|
|
|
|
|
|
const {TemplEmail} = require('../models/templemail');
|
|
|
|
|
|
const {OpzEmail} = require('../models/opzemail');
|
|
|
|
|
|
const {MailingList} = require('../models/mailinglist');
|
|
|
|
|
|
const {Settings} = require('../models/settings');
|
|
|
|
|
|
const {SendMsg} = require('../models/sendmsg');
|
|
|
|
|
|
const {Permission} = require('../models/permission');
|
|
|
|
|
|
const {MsgTemplate} = require('../models/msg_template');
|
2020-12-21 02:16:42 +01:00
|
|
|
|
const Product = require('../models/product');
|
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');
|
2021-01-18 00:48:17 +01:00
|
|
|
|
const ShareWithUs = require('../models/sharewithus');
|
2021-04-30 01:31:12 +02:00
|
|
|
|
const Site = require('../models/site');
|
|
|
|
|
|
const IscrittiConacreis = require('../models/iscrittiConacreis');
|
2021-02-03 01:33:30 +01:00
|
|
|
|
const Group = require('../models/group');
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const {Todo} = require('../models/todo');
|
2021-02-11 02:20:35 +01:00
|
|
|
|
const Hours = require('../models/hours');
|
2020-12-25 03:54:16 +01:00
|
|
|
|
const Order = require('../models/order');
|
2021-05-10 01:50:40 +02:00
|
|
|
|
const Cash = require('../models/cash');
|
|
|
|
|
|
const CashCategory = require('../models/cashCategory');
|
|
|
|
|
|
const CashSubCategory = require('../models/cashSubCategory');
|
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');
|
|
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
const UserCost = {
|
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
|
|
|
|
|
2021-12-21 18:12:28 +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;
|
2020-01-20 01:48:25 +01:00
|
|
|
|
// console.log("LINKVERIF_REG POST " + process.env.LINKVERIF_REG + " idapp= " + idapp + " idlink = " + 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) => {
|
2020-05-04 19:34:41 +02:00
|
|
|
|
console.log(e.message);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Faccio richiesta di una Nuova Password
|
|
|
|
|
|
router.post(process.env.LINK_REQUEST_NEWPASSWORD, (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
|
|
|
|
|
2020-01-30 01:19:25 +01:00
|
|
|
|
User.findByEmail(idapp, email).then(async (user) => {
|
2019-02-05 03:40:22 +01:00
|
|
|
|
if (!user) {
|
2020-01-30 01:19:25 +01:00
|
|
|
|
await 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
|
|
|
|
} else {
|
|
|
|
|
|
// Creo il tokenforgot
|
2021-11-22 18:29:22 +01:00
|
|
|
|
user.tokenforgot = jwt.sign(user._id.toHexString(), process.env.SIGNCODE).
|
|
|
|
|
|
toString();
|
2019-02-05 03:40:22 +01:00
|
|
|
|
user.date_tokenforgot = new Date();
|
2019-10-27 00:37:10 +02:00
|
|
|
|
user.lasttimeonline = new Date();
|
2019-12-07 00:20:06 +01:00
|
|
|
|
user.save().then(async () => {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await sendemail.sendEmail_RequestNewPassword(res.locale, user,
|
|
|
|
|
|
user.email, user.idapp, user.tokenforgot);
|
|
|
|
|
|
res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
2019-02-05 03:40:22 +01:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch((e) => {
|
2020-05-04 19:34:41 +02:00
|
|
|
|
console.log(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});
|
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) => {
|
2020-05-04 19:34:41 +02:00
|
|
|
|
console.log(e.message);
|
2019-02-05 03:40:22 +01:00
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2019-10-15 20:40:31 +02:00
|
|
|
|
function getTableByTableName(tablename) {
|
2019-10-14 20:31:57 +02:00
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
let mytable = '';
|
2019-10-15 20:40:31 +02:00
|
|
|
|
if (tablename === 'users')
|
2019-10-14 20:31:57 +02:00
|
|
|
|
mytable = User;
|
2020-05-10 21:07:51 +02:00
|
|
|
|
else if (tablename === 'tessitura')
|
|
|
|
|
|
mytable = Tessitura;
|
2021-11-22 18:29:22 +01:00
|
|
|
|
// else if (tablename === 'extralist')
|
2020-05-10 21:07:51 +02:00
|
|
|
|
// mytable = ExtraList;
|
2019-10-20 01:21:54 +02:00
|
|
|
|
else if (tablename === 'bookings')
|
2019-10-14 20:31:57 +02:00
|
|
|
|
mytable = Booking;
|
2019-10-20 01:21:54 +02:00
|
|
|
|
else if (tablename === 'operators')
|
|
|
|
|
|
mytable = Operator;
|
2020-12-21 02:16:42 +01:00
|
|
|
|
else if (tablename === 'products')
|
|
|
|
|
|
mytable = Product;
|
2020-12-25 03:54:16 +01:00
|
|
|
|
else if (tablename === 'storehouses')
|
|
|
|
|
|
mytable = Storehouse;
|
2021-02-03 01:33:30 +01:00
|
|
|
|
else if (tablename === 'departments')
|
|
|
|
|
|
mytable = Department;
|
2021-01-18 00:48:17 +01:00
|
|
|
|
else if (tablename === 'sharewithus')
|
|
|
|
|
|
mytable = ShareWithUs;
|
2021-04-30 01:31:12 +02:00
|
|
|
|
else if (tablename === 'sites')
|
|
|
|
|
|
mytable = Site;
|
|
|
|
|
|
else if (tablename === 'iscritticonacreis')
|
|
|
|
|
|
mytable = IscrittiConacreis;
|
2021-02-03 01:33:30 +01:00
|
|
|
|
else if (tablename === 'groups')
|
|
|
|
|
|
mytable = Group;
|
2021-02-11 02:20:35 +01:00
|
|
|
|
else if (tablename === 'todos')
|
|
|
|
|
|
mytable = Todo;
|
|
|
|
|
|
else if (tablename === 'hours')
|
|
|
|
|
|
mytable = Hours;
|
2020-12-25 03:54:16 +01:00
|
|
|
|
else if (tablename === 'orders')
|
|
|
|
|
|
mytable = Order;
|
2021-05-10 01:50:40 +02:00
|
|
|
|
else if (tablename === 'cashs')
|
|
|
|
|
|
mytable = Cash;
|
|
|
|
|
|
else if (tablename === 'cashCategorys')
|
|
|
|
|
|
mytable = CashCategory;
|
|
|
|
|
|
else if (tablename === 'cashSubCategorys')
|
|
|
|
|
|
mytable = CashSubCategory;
|
2020-12-25 03:54:16 +01:00
|
|
|
|
else if (tablename === 'producers')
|
|
|
|
|
|
mytable = Producer;
|
|
|
|
|
|
else if (tablename === 'carts')
|
|
|
|
|
|
mytable = Cart;
|
2021-02-03 01:33:30 +01:00
|
|
|
|
else if (tablename === 'orderscart')
|
|
|
|
|
|
mytable = OrdersCart;
|
2019-10-24 23:30:45 +02:00
|
|
|
|
else if (tablename === 'sendmsgs')
|
|
|
|
|
|
mytable = SendMsg;
|
2019-10-21 20:38:10 +02:00
|
|
|
|
else if (tablename === 'wheres')
|
|
|
|
|
|
mytable = Where;
|
|
|
|
|
|
else if (tablename === 'myevents')
|
2019-10-20 01:21:54 +02:00
|
|
|
|
mytable = MyEvent;
|
2021-12-21 01:27:45 +01:00
|
|
|
|
else if (tablename === 'contribtypes')
|
2019-10-23 23:47:21 +02:00
|
|
|
|
mytable = Contribtype;
|
2020-01-03 01:52:49 +01:00
|
|
|
|
else if (tablename === 'paymenttypes')
|
|
|
|
|
|
mytable = PaymentType;
|
2019-11-12 21:34:03 +01:00
|
|
|
|
else if (tablename === 'disciplines')
|
|
|
|
|
|
mytable = Discipline;
|
2019-11-21 00:18:40 +01:00
|
|
|
|
else if (tablename === 'newstosent')
|
|
|
|
|
|
mytable = Newstosent;
|
2019-12-27 12:41:39 +01:00
|
|
|
|
else if (tablename === 'gallery')
|
|
|
|
|
|
mytable = Gallery;
|
2019-12-07 00:20:06 +01:00
|
|
|
|
else if (tablename === 'mypage')
|
|
|
|
|
|
mytable = MyPage;
|
2021-12-29 18:26:08 +01:00
|
|
|
|
else if (tablename === 'mybots')
|
|
|
|
|
|
mytable = MyBot;
|
2020-01-21 01:37:15 +01:00
|
|
|
|
else if (tablename === 'calzoom')
|
|
|
|
|
|
mytable = CalZoom;
|
2019-12-04 02:03:44 +01:00
|
|
|
|
else if (tablename === 'templemail')
|
|
|
|
|
|
mytable = TemplEmail;
|
|
|
|
|
|
else if (tablename === 'opzemail')
|
|
|
|
|
|
mytable = OpzEmail;
|
2019-11-04 20:30:09 +01:00
|
|
|
|
else if (tablename === 'settings')
|
|
|
|
|
|
mytable = Settings;
|
2019-10-28 16:01:28 +01:00
|
|
|
|
else if (tablename === 'permissions')
|
|
|
|
|
|
mytable = Permission;
|
2019-11-21 00:18:40 +01:00
|
|
|
|
else if (tablename === 'mailinglist')
|
|
|
|
|
|
mytable = MailingList;
|
2020-03-10 21:44:14 +01:00
|
|
|
|
else if (tablename === 'navi')
|
|
|
|
|
|
mytable = Nave;
|
2020-06-08 13:31:05 +02:00
|
|
|
|
else if (tablename === 'flotte')
|
|
|
|
|
|
mytable = Flotta;
|
|
|
|
|
|
else if (tablename === 'msg_templates')
|
|
|
|
|
|
mytable = MsgTemplate;
|
2020-03-25 18:26:51 +01:00
|
|
|
|
else if (tablename === 'navepersistente')
|
|
|
|
|
|
mytable = NavePersistente;
|
2020-03-10 21:44:14 +01:00
|
|
|
|
else if (tablename === 'listaingressos')
|
|
|
|
|
|
mytable = ListaIngresso;
|
2020-05-19 00:18:13 +02:00
|
|
|
|
else if (tablename === 'graduatorias')
|
|
|
|
|
|
mytable = Graduatoria;
|
2021-10-05 00:20:12 +02:00
|
|
|
|
else if (tablename === 'skills')
|
|
|
|
|
|
mytable = Skill;
|
2021-12-31 01:44:28 +01:00
|
|
|
|
else if (tablename === 'subskills')
|
|
|
|
|
|
mytable = SubSkill;
|
2021-10-08 00:38:35 +02:00
|
|
|
|
else if (tablename === 'myskills')
|
|
|
|
|
|
mytable = MySkill;
|
|
|
|
|
|
else if (tablename === 'statusSkills')
|
|
|
|
|
|
mytable = StatusSkill;
|
2021-10-28 00:38:10 +02:00
|
|
|
|
else if (tablename === 'cities')
|
2021-10-08 00:38:35 +02:00
|
|
|
|
mytable = City;
|
2022-01-23 23:25:34 +01:00
|
|
|
|
else if (tablename === 'provinces')
|
|
|
|
|
|
mytable = Province;
|
2021-10-05 00:20:12 +02:00
|
|
|
|
else if (tablename === 'sectors')
|
|
|
|
|
|
mytable = Sector;
|
|
|
|
|
|
else if (tablename === 'levels')
|
|
|
|
|
|
mytable = Level;
|
2021-12-21 01:27:45 +01:00
|
|
|
|
else if (shared_consts.TablePickup.includes(tablename))
|
|
|
|
|
|
mytable = Pickup;
|
2022-01-23 23:25:34 +01:00
|
|
|
|
//else if (shared_consts.TableCities.includes(tablename))
|
|
|
|
|
|
// mytable = City;
|
2019-10-14 20:31:57 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return mytable;
|
2019-10-15 20:40:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
|
router.post('/settable', authenticate, (req, res) => {
|
|
|
|
|
|
const params = req.body;
|
|
|
|
|
|
const mytable = getTableByTableName(params.table);
|
|
|
|
|
|
const mydata = req.body.data;
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
2021-12-23 14:13:40 +01:00
|
|
|
|
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
|
|
|
|
|
!User.isEditor(req.user.perm) && !User.isTutor(req.user.perm)) &&
|
2022-01-16 23:21:03 +01:00
|
|
|
|
!tools.ModificheConsentite(params.table, fieldsvalue)) {
|
2021-12-23 14:13:40 +01:00
|
|
|
|
// If without permissions, exit
|
|
|
|
|
|
return res.status(404).
|
|
|
|
|
|
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-08 00:38:35 +02:00
|
|
|
|
if (shared_consts.TABLES_USER_ID.includes(params.table)) {
|
|
|
|
|
|
mydata.userId = req.user._id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-02 10:13:27 +01:00
|
|
|
|
delete mydata['__v'];
|
|
|
|
|
|
delete mydata['__proto__'];
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let mytablerec = new mytable(mydata);
|
2021-10-08 00:38:35 +02:00
|
|
|
|
// console.log('mytablerec', mytablerec);
|
|
|
|
|
|
|
|
|
|
|
|
const mytablestrutt = getTableByTableName(params.table);
|
|
|
|
|
|
|
2021-12-02 10:13:27 +01:00
|
|
|
|
if (mydata['_id'] !== undefined && mydata['_id'] !== 0) {
|
|
|
|
|
|
mytablerec.isNew = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-21 01:27:45 +01:00
|
|
|
|
if (shared_consts.TABLES_ID_NUMBER.includes(params.table)) {
|
|
|
|
|
|
} else if (params.table === 'hours') {
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (mydata['_id'] === undefined) {
|
|
|
|
|
|
mydata._id = new ObjectID();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return mytablerec.save().then(rec => {
|
|
|
|
|
|
// tools.mylog('rec', rec);
|
|
|
|
|
|
return res.send(rec);
|
2021-10-08 00:38:35 +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-10-08 00:38:35 +02: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);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-10-08 00:38:35 +02:00
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
router.post('/setsubrec', authenticate, (req, res) => {
|
|
|
|
|
|
const params = req.body;
|
|
|
|
|
|
const mytable = getTableByTableName(params.table);
|
|
|
|
|
|
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
|
|
|
|
|
2021-02-11 02:20:35 +01:00
|
|
|
|
const mytablestrutt = 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);
|
|
|
|
|
|
|
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
|
|
|
|
|
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;
|
|
|
|
|
|
const mytable = 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
|
|
|
|
|
2019-10-20 01:21:54 +02:00
|
|
|
|
return mytable.executeQueryTable(req.user.idapp, params).then(ris => {
|
2019-10-14 20:31:57 +02:00
|
|
|
|
return res.send(ris);
|
2019-10-20 01:21:54 +02:00
|
|
|
|
|
2019-10-14 20:31:57 +02:00
|
|
|
|
}).catch((e) => {
|
2022-01-07 01:18:01 +01:00
|
|
|
|
console.log('gettable: ' + e.message);
|
2019-10-14 20:31:57 +02:00
|
|
|
|
res.status(400).send(e);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-12-21 01:27:45 +01:00
|
|
|
|
router.post('/pickup', authenticate, (req, res) => {
|
|
|
|
|
|
const params = req.body;
|
2021-12-21 18:12:28 +01:00
|
|
|
|
let mytable = 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-01-20 00:39:06 +01:00
|
|
|
|
return mytable.executeQueryPickup(req.user.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;
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return MyPage.findOne({idapp, path: mypath}).then((ris) => {
|
|
|
|
|
|
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;
|
|
|
|
|
|
const idapp = req.body.idapp;
|
|
|
|
|
|
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;
|
2020-02-02 04:06:32 +01:00
|
|
|
|
const idapp = req.body.idapp;
|
2019-10-15 20:40:31 +02:00
|
|
|
|
const mydata = req.body.data;
|
|
|
|
|
|
|
|
|
|
|
|
const mytable = getTableByTableName(mydata.table);
|
|
|
|
|
|
const fieldsvalue = mydata.fieldsvalue;
|
2020-07-02 22:00:58 +02:00
|
|
|
|
const unset = mydata.unset;
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
|
// tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
|
2019-10-15 20:40:31 +02:00
|
|
|
|
|
2019-12-29 01:53:51 +01:00
|
|
|
|
// If I change my record...
|
2021-11-22 18:29:22 +01:00
|
|
|
|
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
|
|
|
|
|
!User.isEditor(req.user.perm) && !User.isTutor(req.user.perm)) &&
|
|
|
|
|
|
(req.user._id.toString() !== id) &&
|
|
|
|
|
|
!tools.ModificheConsentite(mydata.table, fieldsvalue)) {
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const camporequisiti = UserCost.FIELDS_REQUISITI.includes(
|
|
|
|
|
|
Object.keys(fieldsvalue)[0]);
|
2020-03-10 21:44:14 +01:00
|
|
|
|
|
|
|
|
|
|
let allData = {};
|
|
|
|
|
|
if (mydata.table === 'users') {
|
|
|
|
|
|
if (camporequisiti) {
|
|
|
|
|
|
allData = {};
|
|
|
|
|
|
allData.myuser = await User.getUserById(idapp, id);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
if (!!allData.myuser)
|
2021-11-22 18:29:22 +01:00
|
|
|
|
allData.precDataUser = await User.getInfoUser(idapp,
|
|
|
|
|
|
allData.myuser.username);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
else
|
|
|
|
|
|
allData.precDataUser = null;
|
2020-05-10 21:07:51 +02:00
|
|
|
|
// allData.useraportador = await ListaIngresso.getUserByInvitante_Username(idapp, allData.myuser.aportador_solidario);
|
|
|
|
|
|
// allData.precDataAportador = await getInfoUser(idapp, allData.myuser.aportador_solidario);
|
2020-03-10 21:44:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
let index = 0;
|
|
|
|
|
|
|
2020-07-02 22:00:58 +02:00
|
|
|
|
let recoldnave = null;
|
|
|
|
|
|
|
|
|
|
|
|
let myuser = null;
|
|
|
|
|
|
let mydatamsg = {};
|
|
|
|
|
|
|
|
|
|
|
|
let flotta = null;
|
|
|
|
|
|
let strflotta = '';
|
|
|
|
|
|
|
2021-10-08 00:38:35 +02:00
|
|
|
|
if (shared_consts.TABLES_UPDATE_LASTMODIFIED.includes(mydata.table)) {
|
|
|
|
|
|
fieldsvalue.date_updated = new Date();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-03 22:48:05 +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) {
|
2021-12-21 18:12:28 +01:00
|
|
|
|
return mytable.deleteMany({_id: myidDel}).then((risdel) => {
|
2021-12-03 22:48:05 +01:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-29 18:26:08 +01:00
|
|
|
|
if (mydata.table === shared_consts.TAB_MYBOTS) {
|
|
|
|
|
|
telegrambot.reloadMenuBot(idapp);
|
|
|
|
|
|
}
|
2021-12-23 14:13:40 +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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-07 01:18:01 +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]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await mytable.findByIdAndUpdate(id, {$set: fieldsvalue}).then(async (rec) => {
|
2019-12-31 00:44:53 +01:00
|
|
|
|
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
2019-10-15 20:40:31 +02:00
|
|
|
|
if (!rec) {
|
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
|
} else {
|
2020-06-08 13:31:05 +02:00
|
|
|
|
let addmsg = '';
|
|
|
|
|
|
|
2020-02-02 04:06:32 +01:00
|
|
|
|
if (mydata.notifBot) {
|
|
|
|
|
|
// Send Notification to the BOT
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await telegrambot.sendMsgTelegram(idapp, mydata.notifBot.un,
|
|
|
|
|
|
mydata.notifBot.txt);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
if (!!addmsg)
|
|
|
|
|
|
await telegrambot.sendMsgTelegram(idapp, mydata.notifBot.un, addmsg);
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let addtext = '[Msg Inviato a ' + mydata.notifBot.un + ']:' + '\n' +
|
|
|
|
|
|
mydata.notifBot.txt;
|
2020-05-11 22:43:14 +02:00
|
|
|
|
telegrambot.sendMsgTelegramToTheManagers(idapp, addtext, true);
|
2020-07-02 22:00:58 +02:00
|
|
|
|
|
|
|
|
|
|
if (!!flotta)
|
|
|
|
|
|
tools.writeFlottaLog(idapp, addtext, flotta.riga, flotta.col_prima);
|
2020-02-02 04:06:32 +01:00
|
|
|
|
}
|
2020-02-05 00:39:25 +01:00
|
|
|
|
|
2020-03-10 21:44:14 +01:00
|
|
|
|
if (mydata.table === 'users') {
|
|
|
|
|
|
if (camporequisiti) {
|
2020-09-04 00:06:49 +02:00
|
|
|
|
await User.checkIfSbloccatiRequisiti(idapp, allData, id);
|
2020-03-10 21:44:14 +01:00
|
|
|
|
}
|
2020-09-04 00:06:49 +02:00
|
|
|
|
|
2020-05-04 19:34:41 +02:00
|
|
|
|
if ('aportador_solidario' in fieldsvalue) {
|
2021-02-18 12:19:35 +01:00
|
|
|
|
let ind_order_ingr = mydata.ind_order_ingr;
|
2020-05-10 21:07:51 +02:00
|
|
|
|
// SERVE SE CI METTO LE MINUSCOLE/MAIUSCOLE SBAGLIATE in invitante_username!
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const myuserfound = await User.findByUsername(idapp,
|
|
|
|
|
|
fieldsvalue.aportador_solidario, false);
|
2020-05-04 19:34:41 +02:00
|
|
|
|
if (!!myuserfound) {
|
|
|
|
|
|
if (!!myuserfound._id && !myuserfound.deleted) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const aportador = await User.getUsernameById(idapp,
|
|
|
|
|
|
myuserfound._id);
|
2020-05-10 21:07:51 +02:00
|
|
|
|
fieldsvalue.aportador_solidario = aportador;
|
2020-05-04 19:34:41 +02:00
|
|
|
|
//Aggiorna record !
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await mytable.findByIdAndUpdate(id, {$set: fieldsvalue});
|
2020-05-10 21:07:51 +02:00
|
|
|
|
|
2020-05-04 19:34:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
res.send(
|
|
|
|
|
|
{code: server_constants.RIS_CODE_ERR, msg: 'Non aggiornato'});
|
2020-05-04 19:34:41 +02:00
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2020-05-19 00:18:13 +02:00
|
|
|
|
} else if ('deleted' in fieldsvalue) {
|
2020-06-08 13:31:05 +02:00
|
|
|
|
let msg = '';
|
|
|
|
|
|
if (fieldsvalue.deleted)
|
|
|
|
|
|
msg = 'cancellato (nascosto)';
|
|
|
|
|
|
else
|
|
|
|
|
|
msg = 'Ripristinato';
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(idapp,
|
|
|
|
|
|
`L\'utente ${rec.name} ${rec.surname} (${rec.username}) è stato ${msg} da ${req.user.name} ${req.user.surname}`);
|
2020-05-04 19:34:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-05 00:39:25 +01:00
|
|
|
|
if (tools.ModificheConsentite(mydata.table, fieldsvalue)) {
|
|
|
|
|
|
let msg = '';
|
|
|
|
|
|
if (mydata.table === 'users') {
|
|
|
|
|
|
if ('aportador_solidario' in fieldsvalue) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const nomecognomenuovo = await User.getNameSurnameByUsername(idapp,
|
|
|
|
|
|
fieldsvalue.aportador_solidario);
|
|
|
|
|
|
const nomecognomeas = await User.getNameSurnameByUsername(idapp,
|
|
|
|
|
|
rec.aportador_solidario);
|
|
|
|
|
|
msg = `Variato l'invitante di ` + rec.name + ' ' + rec.surname +
|
|
|
|
|
|
'\nmodificato da ' + req.user.name + ' ' + req.user.surname +
|
|
|
|
|
|
' \n' +
|
|
|
|
|
|
'Prima: ' + nomecognomeas + ' (' + rec.aportador_solidario +
|
|
|
|
|
|
')\n' +
|
|
|
|
|
|
'Dopo: ' + nomecognomenuovo + ' (' +
|
|
|
|
|
|
fieldsvalue.aportador_solidario + ') ]';
|
2020-03-10 21:44:14 +01:00
|
|
|
|
|
|
|
|
|
|
// Metti l'iniziale
|
|
|
|
|
|
if (!await User.AportadorOrig(id)) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await mytable.findByIdAndUpdate(id,
|
|
|
|
|
|
{$set: {aportador_iniziale: fieldsvalue.aportador_solidario}},
|
|
|
|
|
|
{new: false});
|
2020-03-10 21:44:14 +01:00
|
|
|
|
}
|
2020-02-05 00:39:25 +01:00
|
|
|
|
}
|
2020-03-10 21:44:14 +01:00
|
|
|
|
|
2020-02-05 00:39:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (msg !== '')
|
|
|
|
|
|
telegrambot.sendMsgTelegramToTheManagers(idapp, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
2020-02-02 04:06:32 +01:00
|
|
|
|
|
2019-10-15 20:40:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}).catch((e) => {
|
2020-04-24 10:29:25 +02:00
|
|
|
|
tools.mylogserr('Error patch USER: ', e.message);
|
2019-10-15 20:40:31 +02:00
|
|
|
|
res.status(400).send();
|
2021-11-22 18:29:22 +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;
|
2020-05-19 00:18:13 +02:00
|
|
|
|
const idapp = req.body.idapp;
|
|
|
|
|
|
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) &&
|
|
|
|
|
|
!User.isTutor(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) {
|
|
|
|
|
|
const mytable = getTableByTableName(mydata.table);
|
|
|
|
|
|
const coltoshow = {
|
|
|
|
|
|
[mydata.coltoshow]: 1
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const ris = await mytable.findOne({ _id: id }, coltoshow);
|
|
|
|
|
|
|
|
|
|
|
|
return ris;
|
|
|
|
|
|
} else if (mydata.myfunc === shared_consts.CallFunz.SET_VALBYTABLE) {
|
|
|
|
|
|
const mytable = getTableByTableName(mydata.table);
|
|
|
|
|
|
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;
|
2020-04-24 10:29:25 +02:00
|
|
|
|
const idapp = req.body.idapp;
|
|
|
|
|
|
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) &&
|
|
|
|
|
|
!User.isTutor(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
|
|
|
|
|
|
|
|
|
|
if (mydata.myfunc === shared_consts.CallFunz.SOSTITUISCI) { // SOSTITUISCI
|
2020-05-11 22:43:14 +02:00
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
let username_da_sostituire = mydata.data.username_da_sostituire;
|
2020-05-11 22:43:14 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let myuservecchio = await User.findOne(
|
|
|
|
|
|
{idapp, username: username_da_sostituire});
|
2020-05-13 01:32:27 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let mianavedasost = await Nave.findOne(
|
|
|
|
|
|
{idapp, riga: mydata.data.riga, col: mydata.data.col});
|
2020-05-11 22:43:14 +02:00
|
|
|
|
if (!!mianavedasost) {
|
2020-04-24 10:29:25 +02:00
|
|
|
|
|
2020-05-11 22:43:14 +02:00
|
|
|
|
// Sostituisci l'Utente
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let myusernuovo = await User.getUserShortDataByUsername(idapp,
|
|
|
|
|
|
mydata.data.username);
|
|
|
|
|
|
let navepersistente = await NavePersistente.findByRigaColByDonatore(
|
|
|
|
|
|
idapp, mydata.data.riga, mydata.data.col, 0);
|
2020-04-24 10:29:25 +02:00
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
if (myusernuovo) {
|
2020-05-11 22:43:14 +02:00
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
if (!mydata.data.AddImbarco && mianavedasost.ind_order > 0) {
|
2020-07-02 22:00:58 +02:00
|
|
|
|
|
2020-06-08 13:31:05 +02:00
|
|
|
|
// Controlla prima se è in una Nave Temporanea, allora lo elimina dall'ultima Nave Temporanea
|
2020-05-11 22:43:14 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let miaarrnavi = await Nave.getArrPosizioniByUsername(idapp,
|
|
|
|
|
|
username);
|
2020-05-11 22:43:14 +02:00
|
|
|
|
if (miaarrnavi) {
|
2020-06-08 13:31:05 +02:00
|
|
|
|
miaarrnavi = miaarrnavi.reverse(); // parto dall'ultima
|
2020-05-11 22:43:14 +02:00
|
|
|
|
for (const mianave of miaarrnavi) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let persistente = await NavePersistente.findByRigaColByDonatore(
|
|
|
|
|
|
idapp, mianave.riga, mianave.col, 0);
|
2020-05-11 22:43:14 +02:00
|
|
|
|
if (persistente.provvisoria) {
|
|
|
|
|
|
fieldsvalue = {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
ind_order: -1,
|
2020-05-11 22:43:14 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let ris = await Nave.findByIdAndUpdate(mianave._id,
|
|
|
|
|
|
{$set: fieldsvalue});
|
2020-05-11 22:43:14 +02:00
|
|
|
|
if (!!ris) {
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// rimosso++;
|
2020-05-11 22:43:14 +02:00
|
|
|
|
break; // Rimuovilo solo 1 !
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
if (mianavedasost.ind_order >= 0) {
|
2020-05-13 01:32:27 +02:00
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// ELIMINO LA LISTAINGRESSO CHE STO SOSTITUENDO (SOLO SE NON VIENE USATA DA ALTRA NAVE!)
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let eliminatoingr = await ListaIngresso.eliminaListaIngresso(idapp,
|
|
|
|
|
|
mianavedasost.ind_order, req, mianavedasost.num_tess);
|
2020-07-02 22:00:58 +02:00
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
if (!eliminatoingr) {
|
|
|
|
|
|
return res.send({
|
|
|
|
|
|
code: server_constants.RIS_CODE_ERR,
|
2021-11-22 18:29:22 +01:00
|
|
|
|
msg: 'La Sostituzione non può avvenire ! Contattare Paolo. (ind_order=' +
|
|
|
|
|
|
mianavedasost.ind_order + ')',
|
2021-02-18 12:19:35 +01:00
|
|
|
|
});
|
2020-05-11 22:43:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-13 01:32:27 +02:00
|
|
|
|
if (!!myuservecchio) {
|
2020-06-08 13:31:05 +02:00
|
|
|
|
if (mydata.data.notifBot) {
|
|
|
|
|
|
|
|
|
|
|
|
const mydatamsg = {
|
|
|
|
|
|
tipomsg: tools.TipoMsg.SEND_MSG_A_UTENTE_SOSTITUITO,
|
2021-11-22 18:29:22 +01:00
|
|
|
|
navemediatore: {
|
|
|
|
|
|
riga: navepersistente.riga,
|
|
|
|
|
|
col: navepersistente.col,
|
|
|
|
|
|
},
|
2020-06-08 13:31:05 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
mydatamsg.flotta = await Flotta.getFlottaByNavePersistente(idapp,
|
|
|
|
|
|
navepersistente);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const rismsg = await telegrambot.getMsgByTipoMsg(mydatamsg,
|
|
|
|
|
|
myuservecchio.lang, myuservecchio, false);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
|
|
|
|
|
if (!!rismsg) {
|
|
|
|
|
|
let messaggio = rismsg.body;
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// let mytitle = rismsg.title;
|
2020-06-08 13:31:05 +02:00
|
|
|
|
if (!!messaggio) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await telegrambot.sendMsgTelegram(idapp, myusernuovo.username,
|
|
|
|
|
|
messaggio);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-02 22:00:58 +02:00
|
|
|
|
// Se ha gia delle altre navi, non cancellarlo!
|
|
|
|
|
|
if (!await Nave.checkIfMadeGift(idapp, myuservecchio.username)) {
|
|
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
if (mydata.data.deleteUser && mianavedasost.ind_order > 0) {
|
2020-07-02 22:00:58 +02:00
|
|
|
|
// Metti Deleted allo User
|
|
|
|
|
|
fieldsvalue = {
|
|
|
|
|
|
deleted: true,
|
|
|
|
|
|
date_deleted: new Date(),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await User.findByIdAndUpdate(myuservecchio.id,
|
|
|
|
|
|
{$set: fieldsvalue});
|
|
|
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(idapp,
|
|
|
|
|
|
`L\'utente ${myuservecchio.name} ${myuservecchio.surname} (${myuservecchio.username}) è stato cancellato (nascosto) perchè sostituito (da ${req.user.name} ${req.user.surname} )`);
|
2020-07-02 22:00:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
2020-05-11 22:43:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let ind_order = -1;
|
|
|
|
|
|
let myingr = null;
|
|
|
|
|
|
// Estrai un ind_order dalla Lista, se era ancora in attesa
|
|
|
|
|
|
if (!mydata.data.AddImbarco)
|
2021-11-22 18:29:22 +01:00
|
|
|
|
myingr = await ListaIngresso.findOne(
|
|
|
|
|
|
{idapp, added: false, username: myusernuovo.username});
|
2020-05-11 22:43:14 +02:00
|
|
|
|
|
|
|
|
|
|
if (!!myingr) {
|
|
|
|
|
|
ind_order = myingr.ind_order;
|
|
|
|
|
|
|
|
|
|
|
|
myingr.added = true;
|
|
|
|
|
|
await myingr.save();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Crea un nuovo Ingresso
|
2021-11-22 18:29:22 +01:00
|
|
|
|
myingr = await ListaIngresso.addUserInListaIngresso(idapp,
|
|
|
|
|
|
myuser.username, myuser.username, myuser.lang, false, true,
|
|
|
|
|
|
null, null, true);
|
2020-05-11 22:43:14 +02:00
|
|
|
|
ind_order = myingr.ind_order;
|
|
|
|
|
|
|
|
|
|
|
|
await myingr.save();
|
2020-05-19 00:18:13 +02:00
|
|
|
|
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-19 00:18:13 +02:00
|
|
|
|
// Togliolo dalla Graduatoria!
|
2020-07-02 22:00:58 +02:00
|
|
|
|
await Graduatoria.findOneAndUpdate({
|
2020-05-19 00:18:13 +02:00
|
|
|
|
idapp,
|
2021-11-22 18:29:22 +01:00
|
|
|
|
idListaIngresso: myingr._id,
|
|
|
|
|
|
}, {$set: {ind_order: -1}}, {new: false});
|
2020-05-19 00:18:13 +02:00
|
|
|
|
|
2020-05-11 22:43:14 +02:00
|
|
|
|
// Aggiorna la Nave con il Nuovo
|
2020-04-24 10:29:25 +02:00
|
|
|
|
fieldsvalue = {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
ind_order,
|
2020-04-24 10:29:25 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
2020-05-11 22:43:14 +02:00
|
|
|
|
const dachi = req.user.name + ' ' + req.user.surname;
|
2020-04-24 10:29:25 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return await Nave.findByIdAndUpdate(mianavedasost.id,
|
|
|
|
|
|
{$set: fieldsvalue}).then(async (nave) => {
|
|
|
|
|
|
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
|
|
|
|
|
if (!nave) {
|
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
|
} else {
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const mydatamsg = {
|
|
|
|
|
|
tipomsg: tools.TipoMsg.SEND_MSG_EFFETTUA_IL_DONO,
|
|
|
|
|
|
navemediatore: {
|
|
|
|
|
|
riga: navepersistente.riga,
|
|
|
|
|
|
col: navepersistente.col,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
mydatamsg.flotta = await Flotta.getFlottaByNavePersistente(idapp,
|
|
|
|
|
|
navepersistente);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const rismsg = await telegrambot.getMsgByTipoMsg(mydatamsg,
|
|
|
|
|
|
myusernuovo.lang, myusernuovo, false);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let messaggio = rismsg.body;
|
|
|
|
|
|
let mytitle = rismsg.title;
|
2020-05-13 01:32:27 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
// const myplacca = await Nave.getNavePos(idapp, navepersistente.riga, navepersistente.col);
|
|
|
|
|
|
// messaggio += tools.ACAPO + myplacca;
|
2020-04-24 10:29:25 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let testostaff = '';
|
|
|
|
|
|
if (mydata.notifBot)
|
|
|
|
|
|
testostaff = mydata.notifBot.txt;
|
2020-05-13 01:32:27 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const mymsg = testostaff + ' ' + myusernuovo.name + ' ' +
|
|
|
|
|
|
myusernuovo.surname + ' [da ' + dachi + ']' + tools.ACAPO +
|
|
|
|
|
|
'Inviato messaggio: ' + messaggio;
|
2020-04-24 10:29:25 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
if (mydata.data.notifBot) {
|
2020-05-11 22:43:14 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await telegrambot.sendMsgTelegram(idapp, myusernuovo.username,
|
|
|
|
|
|
messaggio);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
if (mydata.data.inviaemail) {
|
|
|
|
|
|
await sendemail.sendEmail_ByText(myusernuovo.lang,
|
|
|
|
|
|
myusernuovo.email, myusernuovo, idapp, {
|
|
|
|
|
|
emailbody: messaggio,
|
|
|
|
|
|
emailtitle: mytitle,
|
|
|
|
|
|
});
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(idapp,
|
|
|
|
|
|
testostaff);
|
|
|
|
|
|
await telegrambot.sendMsgTelegram(idapp, req.user.username,
|
|
|
|
|
|
testostaff);
|
|
|
|
|
|
// await telegrambot.sendMsgTelegram(idapp, req.user.username, myplacca);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tools.writeManagersLog(mymsg);
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const msgsost = '[NAVE ' + navepersistente.riga + '.' +
|
|
|
|
|
|
navepersistente.col + '] Sostituito ' +
|
|
|
|
|
|
myuservecchio.username + ' (' + myuservecchio.name + ' ' +
|
|
|
|
|
|
myuservecchio.surname + ') ' + ' con -> ' +
|
|
|
|
|
|
myusernuovo.username + ' (' + myusernuovo.name + ' ' +
|
|
|
|
|
|
myusernuovo.surname + '' +
|
|
|
|
|
|
') [Posiz. ' + nave.riga + '.' + nave.col + ' ind_order=' +
|
|
|
|
|
|
nave.ind_order + '] ' + ' [da ' + dachi + ']';
|
|
|
|
|
|
tools.writeSostituzioniLog(msgsost);
|
|
|
|
|
|
tools.writeFlottaLog(idapp, msgsost, mydatamsg.flotta.riga,
|
|
|
|
|
|
mydatamsg.flotta.col_prima);
|
|
|
|
|
|
await telegrambot.sendMsgTelegramToTheManagers(idapp, msgsost,
|
|
|
|
|
|
false);
|
|
|
|
|
|
|
|
|
|
|
|
// const nomecognomeprima = myuser.name + ' ' + myuser.surname + '(' + myuser.username + ')';
|
|
|
|
|
|
// const nomecognomenuovo = await User.getNameSurnameByUsername(idapp,);
|
|
|
|
|
|
|
|
|
|
|
|
res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
|
tools.mylogserr('Error patch USER: ', e.message);
|
|
|
|
|
|
res.status(400).send();
|
|
|
|
|
|
});
|
2020-05-11 22:43:14 +02:00
|
|
|
|
}
|
2020-04-24 10:29:25 +02:00
|
|
|
|
}
|
2021-11-22 18:29:22 +01:00
|
|
|
|
} else if (mydata.myfunc ===
|
|
|
|
|
|
shared_consts.CallFunz.AGGIUNGI_NUOVO_IMBARCO) {
|
2020-05-04 19:34:41 +02:00
|
|
|
|
// Ottieni il prossimo Numero di Tessitura
|
2020-05-10 21:07:51 +02:00
|
|
|
|
//let num_tess = await Nave.getNextNumTess(idapp, ind_order);
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// const num_tess = 1;
|
2020-05-04 19:34:41 +02:00
|
|
|
|
|
2020-05-10 21:07:51 +02:00
|
|
|
|
/*
|
2020-05-04 19:34:41 +02:00
|
|
|
|
let listaingr = await ListaIngresso.find({ idapp, ind_order }).sort({ num_tess: 1 });
|
|
|
|
|
|
const trovato = listaingr.find((rec) => rec.num_tess === num_tess);
|
|
|
|
|
|
if (trovato) {
|
|
|
|
|
|
num_tess = listaingr.slice(-1)[0].num_tess + 2;
|
|
|
|
|
|
}
|
2020-05-10 21:07:51 +02:00
|
|
|
|
*/
|
2020-05-04 19:34:41 +02:00
|
|
|
|
|
2020-05-10 21:07:51 +02:00
|
|
|
|
// metti l'invitante inizialmente a Te stesso !
|
|
|
|
|
|
const invitante_username = req.body.data.invitante_username;
|
2020-05-04 19:34:41 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await ListaIngresso.addUserInListaIngresso(idapp, username,
|
|
|
|
|
|
invitante_username, myuser.lang, true, true);
|
2020-05-10 21:07:51 +02:00
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
let arrimbarchi = await ListaIngresso.findAllByUsername(idapp, username);
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_OK, arrimbarchi});
|
2020-05-10 21:07:51 +02:00
|
|
|
|
|
2020-05-04 19:34:41 +02:00
|
|
|
|
} else if (mydata.myfunc === shared_consts.CallFunz.CANCELLA_IMBARCO) {
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const myrec = await ListaIngresso.getIngrEUserByFilter(idapp,
|
|
|
|
|
|
{idapp, _id: ObjectID(mydata.data.id)});
|
2020-05-19 00:18:13 +02:00
|
|
|
|
|
|
|
|
|
|
if (!!myrec) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await ListaIngresso.find({_id: mydata.data.id});
|
2020-05-19 00:18:13 +02:00
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
const risdel = await ListaIngresso.eliminaListaIngresso(idapp,
|
|
|
|
|
|
mydata.ind_order, req, mydata.data.num_tess);
|
2020-06-08 13:31:05 +02:00
|
|
|
|
|
2020-07-02 22:00:58 +02:00
|
|
|
|
if (risdel) {
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return res.send({code: server_constants.RIS_CODE_OK, msg: ''});
|
2020-05-19 00:18:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-05-04 19:34:41 +02:00
|
|
|
|
|
2020-09-04 00:06:49 +02:00
|
|
|
|
} else if (mydata.myfunc === shared_consts.CallFunz.ZOOM_GIA_PARTECIPATO) {
|
|
|
|
|
|
|
|
|
|
|
|
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) => {
|
2020-02-05 00:39:25 +01:00
|
|
|
|
// const idapporig = req.params.idapporig;
|
|
|
|
|
|
// const idappdest = req.params.idappdest;
|
|
|
|
|
|
// if (!idapporig || !idappdest)
|
|
|
|
|
|
// res.status(400).send();
|
|
|
|
|
|
//
|
|
|
|
|
|
// const mytablesstr = ['settings', 'users', 'templemail', 'contribtype'];
|
|
|
|
|
|
//
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// let numrectot = 0;
|
|
|
|
|
|
// for (const table of mytablesstr) {
|
|
|
|
|
|
// const mytable = getTableByTableName(table);
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
const mytable = getTableByTableName(tablename);
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// 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) {
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
2019-10-20 22:45:09 +02:00
|
|
|
|
router.post('/duprec/:table/:id', authenticate, (req, res) => {
|
|
|
|
|
|
const id = req.params.id;
|
|
|
|
|
|
const tablename = req.params.table;
|
|
|
|
|
|
// const idapp = req.body.idapp;
|
|
|
|
|
|
|
|
|
|
|
|
console.log('id', id, 'table', tablename);
|
|
|
|
|
|
|
|
|
|
|
|
const mytable = getTableByTableName(tablename);
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-21 20:38:10 +02:00
|
|
|
|
return mytable.findById(id).then((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
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return mynewrec.save().then((rec) => {
|
|
|
|
|
|
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
|
|
|
|
|
|
return actions.doOtherThingsAfterDuplicated(tablename, rec).
|
|
|
|
|
|
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);
|
|
|
|
|
|
});
|
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) {
|
2021-12-23 14:13:40 +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
|
|
|
|
|
2021-12-23 14:13:40 +01:00
|
|
|
|
|
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
|
2021-12-23 14:13:40 +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);
|
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);
|
|
|
|
|
|
let skills = Skill.findAllIdApp(idapp);
|
2021-12-31 01:44:28 +01:00
|
|
|
|
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);
|
2021-10-28 00:38:10 +02:00
|
|
|
|
let cities = City.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-01-14 23:54:33 +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-01-20 00:39:06 +01: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,
|
|
|
|
|
|
skills,
|
2021-12-31 01:44:28 +01:00
|
|
|
|
subSkills,
|
2021-11-22 18:29:22 +01:00
|
|
|
|
sectors,
|
|
|
|
|
|
statusSkills,
|
2022-01-20 00:39:06 +01:00
|
|
|
|
cities,
|
|
|
|
|
|
myuserextra]).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-01-20 00:39:06 +01:00
|
|
|
|
myuser = arrdata[30];
|
|
|
|
|
|
if (myuser) {
|
|
|
|
|
|
myuser.password = '';
|
|
|
|
|
|
myuser._doc.calcstat = arrdata[13];
|
|
|
|
|
|
}
|
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],
|
2021-12-31 01:44:28 +01:00
|
|
|
|
subSkills: arrdata[26],
|
|
|
|
|
|
sectors: arrdata[27],
|
|
|
|
|
|
statusSkills: arrdata[28],
|
|
|
|
|
|
cities: arrdata[29],
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
await cfgserver.find({idapp}).then((arrcfgrec) => {
|
2019-10-24 23:30:45 +02:00
|
|
|
|
|
|
|
|
|
|
if (!arrcfgrec)
|
|
|
|
|
|
return res.status(404).send();
|
|
|
|
|
|
|
|
|
|
|
|
// ++Todo: Add to Log Stat ....
|
|
|
|
|
|
|
|
|
|
|
|
// const sall = '0';
|
|
|
|
|
|
|
2019-10-25 19:08:38 +02:00
|
|
|
|
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
|
2021-11-22 18:29:22 +01:00
|
|
|
|
let last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId,
|
|
|
|
|
|
req.user.username, req.user.idapp);
|
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
|
2021-05-10 01:50:40 +02:00
|
|
|
|
usersList = User.getUsersList(req.user.idapp);
|
2021-02-18 12:19:35 +01:00
|
|
|
|
// usersList = null;
|
2019-10-24 23:30:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
return Promise.all([usersList, last_msgs]).then((arrdata) => {
|
|
|
|
|
|
// console.table(arrdata);
|
|
|
|
|
|
return res.send({
|
|
|
|
|
|
cfgServer: arrcfgrec,
|
|
|
|
|
|
usersList: arrdata[0],
|
|
|
|
|
|
last_msgs: arrdata[1],
|
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);
|
2019-12-27 12:41:39 +01:00
|
|
|
|
const idapp = req.user.idapp;
|
|
|
|
|
|
|
|
|
|
|
|
const form = new formidable.IncomingForm();
|
|
|
|
|
|
|
|
|
|
|
|
form.parse(req);
|
|
|
|
|
|
|
2021-10-05 00:20:12 +02:00
|
|
|
|
let dirmain = '/statics';
|
2022-01-07 01:18:01 +01:00
|
|
|
|
console.log('process.env.PROD', process.env.PROD);
|
2021-10-05 00:20:12 +02:00
|
|
|
|
if (version > 0) {
|
2022-01-07 01:18:01 +01:00
|
|
|
|
if (process.env.PROD === '1') {
|
2021-10-28 00:38:10 +02:00
|
|
|
|
dirmain = '';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
dirmain = '/public';
|
|
|
|
|
|
}
|
2021-10-05 00:20:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-27 12:41:39 +01:00
|
|
|
|
form.uploadDir = folder + '/' + dir;
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
form.on('fileBegin', async function(name, file) {
|
2019-12-27 12:41:39 +01:00
|
|
|
|
file.path = folder + '/' + file.name;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-11-22 18:29:22 +01:00
|
|
|
|
form.on('file', async function(name, file) {
|
2019-12-27 12:41:39 +01:00
|
|
|
|
try {
|
|
|
|
|
|
console.log('Uploaded ' + file.name);
|
2022-01-12 00:38:47 +01:00
|
|
|
|
const mydir = tools.getdirByIdApp(idapp) + dirmain + server_constants.DIR_UPLOAD + '/' + dir;
|
2019-12-28 14:30:30 +01:00
|
|
|
|
|
|
|
|
|
|
// Create Dir if doesn't exist:
|
|
|
|
|
|
tools.mkdirpath(mydir);
|
2022-01-23 23:25:34 +01:00
|
|
|
|
|
|
|
|
|
|
let filename = file.name;
|
|
|
|
|
|
let ext = path.extname(filename);
|
|
|
|
|
|
|
|
|
|
|
|
//++Todo: Modifica del nomefile... da passare al frontend
|
|
|
|
|
|
//if (mydir.includes('profile')) {
|
|
|
|
|
|
// filename = uuidv4() + ext;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
file.name = filename
|
2021-02-18 12:19:35 +01:00
|
|
|
|
let newname = mydir + '/' + file.name;
|
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
|
|
|
|
|
|
|
|
|
|
console.log('move from ', file.path, 'to :', newname);
|
2019-12-07 00:20:06 +01:00
|
|
|
|
|
2019-12-27 12:41:39 +01:00
|
|
|
|
// For local: ... resolve this... sending through the static folder...
|
2022-01-23 23:25:34 +01:00
|
|
|
|
// res.sendFile(path.resolve(filename));
|
|
|
|
|
|
|
|
|
|
|
|
oldpath = file.path
|
|
|
|
|
|
file.path = newname;
|
2019-12-27 12:41:39 +01:00
|
|
|
|
|
2019-12-28 14:30:30 +01:00
|
|
|
|
// Move in the folder application !
|
2022-01-23 23:25:34 +01:00
|
|
|
|
tools.move(oldpath, newname, (err) => {
|
2020-02-02 04:06:32 +01:00
|
|
|
|
if (err)
|
|
|
|
|
|
console.log('err:', err);
|
2021-12-21 18:12:28 +01:00
|
|
|
|
|
|
|
|
|
|
const setup_image_compress = {
|
|
|
|
|
|
all: {
|
|
|
|
|
|
path: mydir + '/',
|
|
|
|
|
|
quality: 80,
|
|
|
|
|
|
},
|
|
|
|
|
|
versions: [
|
|
|
|
|
|
{
|
|
|
|
|
|
prefix: server_constants.PREFIX_IMG,
|
|
|
|
|
|
width: 512,
|
|
|
|
|
|
height: 512,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
quality: 100,
|
|
|
|
|
|
prefix: server_constants.PREFIX_IMG_SMALL,
|
|
|
|
|
|
width: 64,
|
|
|
|
|
|
height: 64,
|
|
|
|
|
|
}],
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Salva le immagini in formato compresso
|
|
|
|
|
|
(async () => {
|
|
|
|
|
|
await resizer(newname, setup_image_compress);
|
|
|
|
|
|
|
|
|
|
|
|
tools.delete(newname, false, () => {})
|
|
|
|
|
|
|
|
|
|
|
|
tools.move(resized_img, newname, (err) => {
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
})();
|
2022-01-26 01:31:22 +01:00
|
|
|
|
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() {
|
|
|
|
|
|
console.log('-> upload done');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
if (process.env.PROD !== 1) {
|
|
|
|
|
|
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;
|