Circuits...

Circuits Fido e Max Qta
Fixed error eslint: 7.0.0 is OK
This commit is contained in:
Paolo Arena
2022-09-11 11:45:33 +02:00
parent d262f94315
commit d62888083b
100 changed files with 3699 additions and 2774 deletions

View File

@@ -14,7 +14,7 @@ const {ObjectID} = require('mongodb');
// const {ListaIngresso} = require('../models/listaingresso');
const {Graduatoria} = require('../models/graduatoria');
const mongoose = require('mongoose').set('debug', false);
const mongoose = require('mongoose').set('debug', process.env.DEBUG);
const {CfgServer} = require('../models/cfgserver');
// const uuidv4 = require('uuid/v4'); // I chose v4 you can select others
@@ -198,14 +198,14 @@ router.post(process.env.LINK_UPDATE_PWD, (req, res) => {
});
router.post('/testServer', authenticate_noerror, (req, res) => {
router.post('/testServer', authenticate_noerror, async (req, res) => {
try {
const test = req.body.test;
let ris = {test};
if (req.user) {
tools.sendNotificationToUser(req.user._id, 'Test Server',
await tools.sendNotificationToUser(req.user._id, 'Test Server',
'Test Server OK',
'/', '', 'server', []);
}
@@ -223,7 +223,7 @@ router.post('/settable', authenticate, async (req, res) => {
const mytable = globalTables.getTableByTableName(params.table);
let mydata = req.body.data;
let extrarec = {};
if (myapp.hasOwnProperty('extrarec')) {
if (mydata && mydata.hasOwnProperty('extrarec')) {
extrarec = mydata['extrarec'];
delete mydata['extrarec'];
}
@@ -343,7 +343,7 @@ router.post('/settable', authenticate, async (req, res) => {
mytablerec.date_updated = new Date();
}
return mytablerec.save().
return await mytablerec.save().
then(async (rec) => {
if (shared_consts.TABLES_GETCOMPLETEREC.includes(params.table)) {
@@ -399,7 +399,7 @@ router.post('/settable', authenticate, async (req, res) => {
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
// nuovo Record:
// aggiungi il creatore al gruppo stesso
return User.setGroupsCmd(mydata.idapp, req.user.username,
return await User.setGroupsCmd(mydata.idapp, req.user.username,
myrec.groupname,
shared_consts.GROUPSCMD.SETGROUP, true, req.user.username).then((ris) => {
return res.send(myrec);
@@ -407,14 +407,14 @@ router.post('/settable', authenticate, async (req, res) => {
} else if (params.table === shared_consts.TAB_MYCIRCUITS && isnewrec) {
// nuovo Record:
// aggiungi il creatore al Circuito stesso
return User.setCircuitCmd(mydata.idapp, req.user.username, myrec.name,
return await User.setCircuitCmd(mydata.idapp, req.user.username, myrec.name,
shared_consts.CIRCUITCMD.SET, true, req.user.username, extrarec).then((ris) => {
return res.send(myrec);
});
}
return res.send(myrec);
}).catch((e) => {
}).catch(async (e) => {
console.error('settable', e.message);
if (e.code === 11000) {
const id = mytablerec._id;
@@ -423,7 +423,7 @@ router.post('/settable', authenticate, async (req, res) => {
if (!myfields.userId) {
myfields.userId = req.user._id.toString();
}
return mytablestrutt.findByIdAndUpdate(id, {$set: myfields}).
return await mytablestrutt.findByIdAndUpdate(id, {$set: myfields}).
then(async (rec) => {
return res.send(rec);
}).
@@ -465,10 +465,12 @@ router.post('/setsubrec', authenticate, (req, res) => {
return res.send(rec);
return mytablerec.save().then(rec => {
// tools.mylog('rec', rec);
return res.send(rec);
}).catch((e) => {
if (e.code === 11000) {
const id = mytablerec._id;
@@ -598,7 +600,7 @@ router.post('/getpage', async (req, res) => {
const idapp = req.body.idapp;
const mypath = params.path;
return MyPage.findOne({idapp, path: mypath}).then((ris) => {
return await MyPage.findOne({idapp, path: mypath}).then((ris) => {
return res.send({mypage: ris});
}).catch((e) => {
console.log(e.message);
@@ -1061,7 +1063,7 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
});
router.post('/duprec/:table/:id', authenticate, (req, res) => {
router.post('/duprec/:table/:id', authenticate, async (req, res) => {
const id = req.params.id;
const tablename = req.params.table;
// const idapp = req.body.idapp;
@@ -1081,12 +1083,12 @@ router.post('/duprec/:table/:id', authenticate, (req, res) => {
send({code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: ''});
}
return mytable.findById(id).then((mydata) => {
return await mytable.findById(id).then(async (mydata) => {
const datadup = tools.CloneRecordToNew(mydata);
const mynewrec = new mytable(datadup);
return mynewrec.save().then((rec) => {
return await mynewrec.save().then(async (rec) => {
if (!rec) {
return res.status(404).send();
}
@@ -1094,7 +1096,7 @@ router.post('/duprec/:table/:id', authenticate, (req, res) => {
tools.mylog('DUPLICATED ', rec);
// Do extra things after deleted
return actions.doOtherThingsAfterDuplicated(tablename, rec).
return await actions.doOtherThingsAfterDuplicated(tablename, rec).
then(({myrec}) => {
// ...
mytable.findById(myrec._id).then((record) => {
@@ -1503,19 +1505,19 @@ function uploadFile(req, res, version) {
try {
form.on('fileBegin', async function(name, file) {
file.path = folder + '/' + file.name;
file.path = folder + '/' + file.newFilename;
});
form.on('file', async function(name, file) {
try {
console.log('1) Uploading ' + file.name);
console.log('1) Uploading ' + file.originalFilename);
const mydir = tools.getdirByIdApp(idapp) + dirmain +
server_constants.DIR_UPLOAD + '/' + dir;
// Create Dir if doesn't exist:
const rismk = tools.mkdirpath(mydir);
let filename = file.name;
let filename = file.originalFilename;
let ext = path.extname(filename);
//++Todo: Modifica del nomefile... da passare al frontend
@@ -1524,10 +1526,10 @@ function uploadFile(req, res, version) {
//}
file.name = filename;
let newname = mydir + '/' + file.name;
let newname = mydir + '/' + file.originalFilename;
let resized_img = mydir + '/' + server_constants.PREFIX_IMG + filename;
oldpath = file.path;
oldpath = file.newFilename;
file.path = newname;
if (!tools.sulServer()) {