Fix _id new in Wheres table /settable

This commit is contained in:
Paolo Arena
2022-09-19 19:40:30 +02:00
parent 3c550595f0
commit 8ad85bbe94
4 changed files with 27 additions and 10 deletions

View File

@@ -231,6 +231,7 @@ CircuitSchema.statics.getWhatToShow = function(idapp, username) {
nome_valuta: 1, nome_valuta: 1,
fido_scoperto_default: 1, fido_scoperto_default: 1,
qta_max_default: 1, qta_max_default: 1,
valuta_per_euro: 1,
symbol: 1, symbol: 1,
idCity: 1, idCity: 1,
pub_to_share: 1, pub_to_share: 1,
@@ -269,6 +270,7 @@ CircuitSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
totTransato: 1, totTransato: 1,
fido_scoperto_default: 1, fido_scoperto_default: 1,
qta_max_default: 1, qta_max_default: 1,
valuta_per_euro: 1,
symbol: 1, symbol: 1,
color: 1, color: 1,
idCity: 1, idCity: 1,

View File

@@ -331,8 +331,8 @@ router.post('/settable', authenticate, async (req, res) => {
} else if (params.table === 'hours') { } else if (params.table === 'hours') {
} else { } else {
if (mydata['_id'] === undefined || (mytablerec.isNew && mydata['_id'] === 0)) { if ((mydata['_id'] === undefined || (mytablerec.isNew && mydata['_id'] === 0)) && (mytablerec._id === undefined)) {
mydata._id = new ObjectID(); mytablerec._id = new ObjectID();
} }
} }
@@ -1522,6 +1522,7 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
function uploadFile(req, res, version) { function uploadFile(req, res, version) {
// console.log('/upload dir:' + dir); // console.log('/upload dir:' + dir);
const dir = tools.invertescapeslash(req.params.dir); const dir = tools.invertescapeslash(req.params.dir);
console.log('inverted = ', dir);
const idapp = req.user.idapp; const idapp = req.user.idapp;
const form = new formidable.IncomingForm(); const form = new formidable.IncomingForm();
@@ -1537,11 +1538,15 @@ function uploadFile(req, res, version) {
} }
} }
form.uploadDir = folder + '/' + dir; const mydir2 = folder + '/' + dir;
tools.mkdirpath(mydir2);
form.uploadDir = mydir2;
try { try {
form.on('fileBegin', async function(name, file) { form.on('fileBegin', async function(name, file) {
file.path = folder + '/' + file.newFilename; const mydir = folder + '/' + file.newFilename;
// tools.mkdirpath(mydir);
file.path = mydir
}); });
form.on('file', async function(name, file) { form.on('file', async function(name, file) {
@@ -1550,6 +1555,8 @@ function uploadFile(req, res, version) {
const mydir = tools.getdirByIdApp(idapp) + dirmain + const mydir = tools.getdirByIdApp(idapp) + dirmain +
server_constants.DIR_UPLOAD + '/' + dir; server_constants.DIR_UPLOAD + '/' + dir;
// console.log('mydir', mydir);
// Create Dir if doesn't exist: // Create Dir if doesn't exist:
const rismk = tools.mkdirpath(mydir); const rismk = tools.mkdirpath(mydir);
@@ -1562,11 +1569,19 @@ function uploadFile(req, res, version) {
//} //}
file.name = filename; file.name = filename;
let newname = mydir + '/' + file.originalFilename;
let resized_img = mydir + '/' + server_constants.PREFIX_IMG + filename; let resized_img = mydir + '/' + server_constants.PREFIX_IMG + filename;
oldpath = file.newFilename; oldpath = file.newFilename;
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;
file.path = newname; file.path = newname;
// console.log('fromfile', fromfile)
// console.log('tofile', tofile);
if (!tools.sulServer()) { if (!tools.sulServer()) {
res.end(); res.end();
@@ -1574,7 +1589,7 @@ function uploadFile(req, res, version) {
} }
// Move in the folder application ! // Move in the folder application !
tools.move(oldpath, newname, (err) => { tools.move(fromfile, tofile, (err) => {
if (err) { if (err) {
console.log('err uploadDir:', err); console.log('err uploadDir:', err);
res.status(400).send(); res.status(400).send();
@@ -1642,7 +1657,7 @@ function uploadFile(req, res, version) {
}); });
form.on('end', function() { form.on('end', function() {
// console.log('-> upload done'); console.log('-> upload done');
}); });
form.on('aborted', () => { form.on('aborted', () => {

View File

@@ -133,7 +133,7 @@ router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res
}); });
router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => { router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
tools.mylog('GET NotifS : ', req.params); // tools.mylog('GET NotifS : ', req.params);
const username = req.params.username; const username = req.params.username;
const lastdataread = req.params.lastdataread; const lastdataread = req.params.lastdataread;
const idapp = req.params.idapp; const idapp = req.params.idapp;

View File

@@ -1460,7 +1460,7 @@ module.exports = {
if (dirmain) { if (dirmain) {
if (!this.sulServer()) { if (!this.sulServer()) {
mypath += '/public'; mypath += 'public';
} }
} }
} }
@@ -3145,7 +3145,7 @@ module.exports = {
}, },
invertescapeslash(mystr) { invertescapeslash(mystr) {
return mystr.replace(/-/g, '/'); return mystr.replace(/Ç/g, '/');
}, },
isNumber(n) { isNumber(n) {