- Cataloghi

- Import ed Export Pagine
- ObjectID sostituita con ObjectId
This commit is contained in:
Surya Paolo
2024-12-17 17:55:47 +01:00
parent 14b3e18986
commit 300bab2125
91 changed files with 404 additions and 272 deletions

View File

@@ -15,7 +15,7 @@ const { Account } = require('../models/account');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
async function getCircuitRecAdminsInfo(idapp, data) {

View File

@@ -634,7 +634,7 @@ router.post('/import', authenticate, async (req, res) => {
let imported = 0;
let errors = 0;
const ripopola = false;
const ripopola = true;
dataObjects = null;
@@ -650,10 +650,12 @@ router.post('/import', authenticate, async (req, res) => {
if (myarr && ripopola) {
console.log('*** INIZIO IMPORT RIPOPOLAMENTO ... ', myarr.length);
// Cancella la collection ImportaMacros
await ImportaDescr.deleteMany({ idapp });
// Aggiungi i record su ImportaMacros
// Aggiungi i record su ImportaDescr
for (const recinv of myarr) {
let isnuovo = false
let setta = false
@@ -669,12 +671,15 @@ router.post('/import', authenticate, async (req, res) => {
let queryprod = { idapp, code: recmacro._id };
try {
let risrec = await ImportaDescr.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
// non inserisce nuovi record, se non lo trova ! perché sono troppi !
let risrec = await ImportaDescr.findOneAndUpdate(queryprod,
{ $set: recmacro }, { new: true, upsert: true, strict: false }
);
if (risrec) {
imported++;
// if (imported > 1000)
// break;
if (imported % 10 === 0)
if (imported % 50 === 0)
console.log('importato ', imported, 'su ', myarr.length);
}
@@ -717,23 +722,23 @@ router.post('/import', authenticate, async (req, res) => {
// IMPOSTA I VALORI SOLO SE NON ESISTONO ! ALTRIMENTI LASCIA QUELLI GIA' IMPORTATI (O MODIFICATI)
if (getvalueByJsonText(product.url)) {
if (!myproductInfo.link_macro)
if ((myproductInfo && !myproductInfo.link_macro) || !myproductInfo)
productInfo.link_macro = getvalueByJsonText(product.url);
}
if (getvalueByJsonText(product.descrizione)) {
if (!myproductInfo.descrizione_completa_macro)
if ((myproductInfo && !myproductInfo.descrizione_breve_macro) || !myproductInfo)
productInfo.descrizione_breve_macro = getvalueByJsonText(product.descrizione);
}
if (getvalueByJsonText(product.descrizione_completa)) {
if (!myproductInfo.descrizione_completa_macro)
if ((myproductInfo && !myproductInfo.descrizione_completa_macro) || !myproductInfo)
productInfo.descrizione_completa_macro = getvalueByJsonText(product.descrizione_completa)
}
if (getvalueByJsonText(product.sottotitolo)) {
if (!myproductInfo.sottotitolo)
if ((myproductInfo && !myproductInfo.sottotitolo) || !myproductInfo)
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo);
}
if (getvalueByJsonText(product.titolo)) {
if (!myproductInfo.name)
if ((myproductInfo && !myproductInfo.name) || !myproductInfo)
productInfo.name = getvalueByJsonText(product.titolo);
}
@@ -756,7 +761,7 @@ router.post('/import', authenticate, async (req, res) => {
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
indprod++;
if (indprod % 10 === 0)
if (indprod % 50 === 0)
console.log(indprod + '/' + numprod);
}
}
@@ -783,14 +788,14 @@ router.post('/import', authenticate, async (req, res) => {
if (dataObjects && dataObjects[0]) {
// Cancella la collection ImportaMacros
// Cancella la collection ImportaIsbn
await ImportaIsbn.deleteMany({ idapp });
const numtot = dataObjects[0].length
console.log('Numero di RECORD da Importare = ', numtot);
// Aggiungi i record su ImportaMacros
// Aggiungi i record su ImportaIsbn
for (const recinv of dataObjects[0]) {
let recmacro = recinv;
@@ -809,7 +814,7 @@ router.post('/import', authenticate, async (req, res) => {
let risrec = await ImportaIsbn.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
if (risrec) {
imported++;
if ((imported % 10) === 0)
if ((imported % 50) === 0)
console.log('Importati dir TEMPORANEA ... ', imported + '/' + numtot);
}
@@ -836,11 +841,11 @@ router.post('/import', authenticate, async (req, res) => {
// Rimuove prima tutti i valori precedenti
let risupdate = await ProductInfo.updateMany({ idapp }, {
$set: {
totaleVenduti: 0,
venditeLastM: 0,
venditeLast6M: 0,
venditeLastY: 0,
venditeLast2Y: 0,
totVen: 0,
vLastM: 0,
vLast6M: 0,
vLastY: 0,
vLast2Y: 0,
rank3M: 0,
rank6M: 0,
rank1Y: 0,
@@ -876,20 +881,20 @@ router.post('/import', authenticate, async (req, res) => {
// id_wp: product._id,
// name: product.title,
totaleVenduti: product.totaleVenduti || 0,
venditeLastM: product.venditeLastM || 0,
venditeLast6M: product.venditeLast6M || 0,
venditeLastY: product.venditeLastY || 0,
venditeLast2Y: product.venditeLast2Y || 0,
totVen: product.totVen || 0,
vLastM: product.vLastM || 0,
vLast6M: product.vLast6M || 0,
vLastY: product.vLastY || 0,
vLast2Y: product.vLast2Y || 0,
rank3M: product.rank3M || 0,
rank6M: product.rank6M || 0,
rank1Y: product.rank1Y || 0,
}
if (product.DataPubblicazione) {
productInfo.date_publishing = new Date(product.DataPubblicazione);
productInfo.date_pub = new Date(product.DataPubblicazione);
// convert data to timestamp
productInfo.date_publishing_ts = productInfo.date_publishing.getTime();
productInfo.date_pub_ts = productInfo.date_pub.getTime();
}
if (product.dataUltimoOrdine) {
productInfo.dataUltimoOrdine = new Date(product.dataUltimoOrdine);
@@ -897,10 +902,10 @@ router.post('/import', authenticate, async (req, res) => {
// Update ProductInfo
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: false });
if (risrecInfo) {
imported++;
if (imported % 10 === 0)
if (imported % 50 === 0)
console.log('Importati... ', imported + '/' + numprod);
}
}
@@ -965,7 +970,7 @@ router.post('/import', authenticate, async (req, res) => {
let risrec = await Importamacro.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
if (risrec) {
imported++;
if (imported % 10 === 0)
if (imported % 50 === 0)
console.log('Importati su dir Temporanea ', imported);
}
@@ -1034,7 +1039,7 @@ router.post('/import', authenticate, async (req, res) => {
let versione = 0;
if (indprod % 10 === 0)
if (indprod % 50 === 0)
console.log(indprod + '/' + numprod);
@@ -1070,9 +1075,9 @@ router.post('/import', authenticate, async (req, res) => {
/*if (product.Data) {
productInfo.date_publishing = new Date(product.Data * 1000);
productInfo.date_pub = new Date(product.Data * 1000);
// convert data to timestamp
productInfo.date_publishing_ts = productInfo.date_publishing.getTime();
productInfo.date_pub_ts = productInfo.date_pub.getTime();
}*/
productInfo.name = productInfo.name.replace(/ - Usato$| - Nuovo$| - Epub$| - Ebook$| - Mobi$| - DVD$| - Streaming$| - Download$/, "");

View File

@@ -19,7 +19,7 @@ const { Reaction } = require('../models/reaction');
const globalTables = require('../tools/globalTables');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
router.post('/getlist', authenticate_noerror, async function (req, res, next) {

View File

@@ -5,7 +5,7 @@ const Subscription = require('../../models/subscribers');
const { Graduatoria } = require('../../models/graduatoria');
const { User } = require('../../models/user');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
const tools = require('../../tools/general');

View File

@@ -8,7 +8,7 @@ const { authenticate } = require('../middleware/authenticate');
const { Booking } = require('../models/booking');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
const sendemail = require('../sendemail');
@@ -56,7 +56,7 @@ router.post('/', authenticate, (req, res) => {
} else {
// save to database a new record
tools.mylog('save to database a new record');
booking._id = new ObjectID();
booking._id = new ObjectId();
return booking.save().then((writeresult) => {
let idobj = writeresult._id;
@@ -107,7 +107,7 @@ router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
//
// // tools.mylog('GET BOOKINGS : ', req.params);
//
// if (!ObjectID.isValid(userId)) {
// if (!ObjectId.isValid(userId)) {
// return res.status(404).send();
// }
//

View File

@@ -19,7 +19,7 @@ const Order = require('../models/order');
const Variant = require('../models/variant');
const { User } = require('../models/user');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
/*const Department = require('../models/Department')
const Category = require('../models/Category')
@@ -442,7 +442,7 @@ router.post('/:userId/gestord', authenticate, async function (req, res, next) {
$match: {
idGasordine: {
$type: "objectId", // Checks if the field is of type ObjectId
$eq: ObjectID(idGasordine) // Compares the value to a specific ObjectId
$eq: ObjectId(idGasordine) // Compares the value to a specific ObjectId
}
}
}

View File

@@ -17,7 +17,7 @@ const { Account } = require('../models/account');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
async function getCircuitRecAdminsInfo(idapp, data) {

View File

@@ -16,7 +16,7 @@ const Subscription = require('../models/subscribers');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
const { City } = require('../models/city');

View File

@@ -15,7 +15,7 @@ const telegrambot = require('../telegram/telegrambot');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
router.post('/', authenticate, async (req, res) => {
try {

View File

@@ -12,7 +12,8 @@ const sharp = require('sharp');
const { authenticate, authenticate_noerror } = require(
'../middleware/authenticate');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
// const {ListaIngresso} = require('../models/listaingresso');
const { Graduatoria } = require('../models/graduatoria');
@@ -418,8 +419,8 @@ router.post('/settable', authenticate, async (req, res) => {
} else {
if ((mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) && (mytablerec._id === undefined || mytablerec._id === '0')) {
mytablerec._id = new ObjectID();
mydata._id = new ObjectID();
mytablerec._id = new ObjectId();
mydata._id = new ObjectId();
mytablerec.isNew = true;
}
}
@@ -911,25 +912,62 @@ async function exportPage(idapp, pageId) {
}
};
async function upsertRecord(table, record, appId) {
async function upsertRecord(table, record, appId, newIdPage = null) {
let newId = null;
const existingRecord = await table.findOne({ idapp: appId, _id: record._id }); // Assumendo che `record` ha un ID
if (existingRecord) {
if (newIdPage && record.idPage) {
record.idPage = newIdPage;
}
const modif = await table.updateOne({ _id: record._id }, { $set: { ...record, idapp: appId } });
wasModified = modif.nModified > 0;
} else {
const ris = await table.create({
// Se sono sulla tabella mypages
if (table.modelName === 'MyPage') {
// Controlla se esiste già la pagina in questione
const existingRecPage = await table.findOne({ idapp: appId, path: record.path });
if (existingRecPage) {
// Esiste già ! quindi aggiorno questo record, e cancello tutti gli elementi precedenti !
delete record._id;
const modif = await table.updateOne({ _id: existingRecPage._id }, { $set: { ...record, idapp: appId } });
const tableElems = globalTables.getTableByTableName('myelems');
if (tableElems)
risdel = await tableElems.deleteMany({ idapp: appId, idPage: existingRecPage._id });
newId = existingRecPage._id.toString();
return { ImportedRecords: false, newId }; // Torna il numero di record importati (1 in questo caso)
}
}
// Se non esiste, allora la creo, con un id Nuovo !
const existingRecSameID = await table.findOne({ _id: record._id }); // Assumendo che `record` ha un ID
if (existingRecSameID) {
// Se
newId = new ObjectId();
record._id = newId;
}
if (newIdPage && record.idPage) {
record.idPage = newIdPage;
}
const newrec = {
...record,
idapp: appId,
});
};
const ris = await table.create(newrec);
wasModified = !!ris;
}
return wasModified; // Torna il numero di record importati (1 in questo caso)
return { ImportedRecords: wasModified, newId }; // Torna il numero di record importati (1 in questo caso)
}
async function importPage(req, idapp, jsonString) {
try {
console.log('INIZIO importPage');
// Parsing dei dati JSON
const myexp = JSON.parse(jsonString);
@@ -939,12 +977,15 @@ async function importPage(req, idapp, jsonString) {
return;
}
let totalImportedRecords = 0;
let newIdPage = null;
// Ciclo su ogni proprietà di myexp
const importCounts = []; // Array per memorizzare i conteggi di importazione
// Cicla prima sulle pagine
for (const key in myexp) {
if (myexp.hasOwnProperty(key)) {
let ImportedRecordstemp = 0;
const tableName = key;
// Verifica se la tabella esiste
@@ -954,24 +995,61 @@ async function importPage(req, idapp, jsonString) {
if (tableName === 'mypages') {
if (User.isEditor(req.user.perm)) {
for (const page of myexp.mypages) {
totalImportedRecords += await upsertRecord(table, page, idapp) ? 1 : 0;
const { ImportedRecords, newId } = await upsertRecord(table, page, idapp);
if (!newIdPage && newId) {
newIdPage = newId;
}
ImportedRecordstemp += ImportedRecords ? 1 : 0;
}
}
}
totalImportedRecords += ImportedRecordstemp;
} else if (tableName === 'myelems') {
}
if (ImportedRecordstemp > 0)
importCounts.push({ tableName, count: ImportedRecordstemp });
}
}
// Ciclo su ogni proprietà di myexp
for (const key in myexp) {
if (myexp.hasOwnProperty(key)) {
let ImportedRecordstemp = 0;
const tableName = key;
// Verifica se la tabella esiste
if (tableName) {
const table = globalTables.getTableByTableName(tableName);
if (tableName === 'myelems') {
if (User.isEditor(req.user.perm)) {
for (const elem of myexp.myelems) {
totalImportedRecords += await upsertRecord(table, elem, idapp) ? 1 : 0;
const { ImportedRecords, newId } = await upsertRecord(table, elem, idapp, newIdPage);
ImportedRecordstemp += ImportedRecords ? 1 : 0;
}
}
} else if (tableName === 'myusers') {
if (User.isManager(req.user.perm)) {
for (const user of myexp.myusers) {
totalImportedRecords += await upsertRecord(table, user, idapp) ? 1 : 0;
const { ImportedRecords, newId } = await upsertRecord(table, user, idapp);
ImportedRecordstemp += ImportedRecords ? 1 : 0;
}
}
} else if (table && (tableName !== 'mypages')) {
// Tutte le altre tabelle
if (User.isManager(req.user.perm)) {
for (const rec of myexp[key]) {
const { ImportedRecords, newId } = await upsertRecord(table, rec, idapp);
ImportedRecordstemp += ImportedRecords ? 1 : 0;
}
}
}
totalImportedRecords += ImportedRecordstemp;
if (ImportedRecordstemp > 0)
importCounts.push({ tableName, count: ImportedRecordstemp });
}
}
}
@@ -980,7 +1058,7 @@ async function importPage(req, idapp, jsonString) {
console.log(`Importazione completata con successo. Totale record importati: ${totalImportedRecords}`);
}
return { imported: totalImportedRecords };
return { imported: totalImportedRecords, importCounts };
} catch (error) {
console.error('Errore durante l\'importazione:', error);
@@ -1387,9 +1465,9 @@ router.patch('/askfunz', authenticate, async (req, res) => {
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 = globalTables.getTableByTableName(mydata.table);
@@ -1397,7 +1475,7 @@ router.patch('/askfunz', authenticate, async (req, res) => {
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 });*/
@@ -2009,7 +2087,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
if (req.user) {
const userId = req.user._id;
if (!ObjectID.isValid(userId)) {
if (!ObjectId.isValid(userId)) {
return res.status(404).send();
}
@@ -2059,29 +2137,29 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
/*
const form = new formidable.IncomingForm();
form.parse(req);
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);
// SSL_OP_NO_TLSv1_2 = 134217728
// console.log('client', client);
form.uploadDir = folder + '/' + dir;
try {
form.on('fileBegin', async function (name, file){
file.path = folder + '/' + file.name;
});
form.on('file', async function (name, file){
try {
// Create directory remote
if (!!dir)
await client.createDir(dir);
const miofile = (dir) ? dir + ` / ` + file.name : file.name;
console.log('Upload...');
const ret = await client.upload(file.path, miofile, 755);
@@ -2098,17 +2176,17 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
res.status(400).send();
}
});
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) {
console.log('Error', e)
}

View File

@@ -2,7 +2,7 @@ const express = require('express');
const router = express.Router();
const IscrittiArcadei = require('../models/iscrittiArcadei');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
const sendemail = require('../sendemail');

View File

@@ -2,7 +2,7 @@ const express = require('express');
const router = express.Router();
const IscrittiConacreis = require('../models/iscrittiConacreis');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
const sendemail = require('../sendemail');

View File

@@ -8,7 +8,7 @@ const {authenticate} = require('../middleware/authenticate');
const {MyEvent} = require('../models/myevent');
const {ObjectID} = require('mongodb');
const {ObjectId} = require('mongodb');
const sendemail = require('../sendemail');
@@ -52,7 +52,7 @@ router.post('/', authenticate, (req, res) => {
} else {
// save to database a new record
tools.mylog('save to database a new record');
myevent._id = new ObjectID();
myevent._id = new ObjectId();
return myevent.save().then((writeresult) => {
let idobj = writeresult._id;
@@ -99,7 +99,7 @@ router.get('/:userId/:idapp/:sall', authenticate, (req, res) => {
// tools.mylog('GET myeventS : ', req.params);
if (!ObjectID.isValid(userId)) {
if (!ObjectId.isValid(userId)) {
return res.status(404).send();
}

View File

@@ -20,7 +20,7 @@ const { Reaction } = require('../models/reaction');
const globalTables = require('../tools/globalTables');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
//GET orders
router.post('/page', authenticate_noerror, function (req, res, next) {

View File

@@ -16,7 +16,7 @@ const _ = require('lodash');
const {MyGood} = require('../models/mygood');
var {User} = require('../models/user');
const {ObjectID} = require('mongodb');
const {ObjectId} = require('mongodb');
//GET orders
router.post('/page', authenticate, function(req, res, next) {

View File

@@ -14,7 +14,7 @@ const { MyGroup } = require('../models/mygroup');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
async function getGroupRecAdminsInfo(idapp, data) {

View File

@@ -16,7 +16,7 @@ const _ = require('lodash');
const {MySkill} = require('../models/myskill');
var {User} = require('../models/user');
const {ObjectID} = require('mongodb');
const {ObjectId} = require('mongodb');
//GET orders
router.post('/page', authenticate, function(req, res, next) {

View File

@@ -16,7 +16,7 @@ const Subscription = require('../models/subscribers');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
const Product = require('../models/product');
const Order = require('../models/order');

View File

@@ -15,7 +15,7 @@ const { User } = require('../models/user');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
router.post('/', authenticate, (req, res) => {
@@ -83,7 +83,7 @@ router.patch('/:id', authenticate, (req, res) => {
tools.mylogshow('PATCH PROJECT: ', id);
if (!ObjectID.isValid(id)) {
if (!ObjectId.isValid(id)) {
tools.mylog('ERROR: id not VALID', id);
return res.status(404).send();
}
@@ -161,7 +161,7 @@ router.get('/:userId', authenticate, (req, res) => {
const idapp = req.query.idapp;
if (!ObjectID.isValid(userId)) {
if (!ObjectId.isValid(userId)) {
return res.status(404).send();
}
@@ -235,7 +235,7 @@ router.delete('/:id', authenticate, (req, res) => {
const hide = true;
if (!ObjectID.isValid(id)) {
if (!ObjectId.isValid(id)) {
return res.status(404).send();
}

View File

@@ -6,7 +6,7 @@ const { Reaction } = require('../models/reaction');
const { User } = require('../models/user');
const Hours = require('../models/hours');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
const sendemail = require('../sendemail');

View File

@@ -19,7 +19,7 @@ const Hours = require('../models/hours');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
router.post('/load', authenticate, async (req, res) => {
let date_start = req.body.date_start;

View File

@@ -12,7 +12,7 @@ const { SendMsg } = require('../models/sendmsg');
const { SendNotif } = require('../models/sendnotif');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
const sendemail = require('../sendemail');
@@ -40,7 +40,7 @@ router.post('/', authenticate, (req, res) => {
// console.log('fieldtochange', fieldtochange);
myrecmsg._id = new ObjectID();
myrecmsg._id = new ObjectId();
return myrecmsg.save()
.then((writeresult) => {
let idobj = writeresult._id;

View File

@@ -15,7 +15,7 @@ const mongoose = require('mongoose').set('debug', false)
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
// const { ExtraList } = require('../models/extralist');

View File

@@ -17,7 +17,7 @@ const { Settings } = require('../models/settings');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
router.get('/', (req, res) => {
@@ -39,7 +39,7 @@ router.get('/', (req, res) => {
};
const myrec = new Todo(todo);
myrec._id = new ObjectID();
myrec._id = new ObjectId();
const TodoOne = myrec.save().then((ris, err) => {
console.log('Err:', err);
@@ -49,7 +49,7 @@ router.get('/', (req, res) => {
const newrec = new Settings({ key: 'chiave1' });
newrec._id = new ObjectID();
newrec._id = new ObjectId();
newrec.idapp = '8';
newrec.save((err, rec) => {

View File

@@ -16,7 +16,7 @@ const Hours = require('../models/hours');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
router.post('/', authenticate, async (req, res) => {
@@ -93,7 +93,7 @@ router.patch('/:id', authenticate, (req, res) => {
// tools.mylogshow('PATCH TODO: ', id);
if (!ObjectID.isValid(id)) {
if (!ObjectId.isValid(id)) {
tools.mylog('ERROR: id not VALID', id);
return res.status(404).send();
}
@@ -160,7 +160,7 @@ router.get('/:userId', authenticate, (req, res) => {
// tools.mylog('GET TODOS : ', req.params);
if (!ObjectID.isValid(userId)) {
if (!ObjectId.isValid(userId)) {
return res.status(404).send();
}
@@ -187,7 +187,7 @@ router.get('/:userId', authenticate, (req, res) => {
router.get('/test', (req, res) => {
const todo = {
_id: new ObjectID(),
_id: new ObjectId(),
// category: "personal",
statustodo: 0,
completed_at: new Date(),
@@ -239,7 +239,7 @@ router.delete('/:id', authenticate, (req, res) => {
let hide = true;
if (!ObjectID.isValid(id)) {
if (!ObjectId.isValid(id)) {
return res.status(404).send();
}

View File

@@ -14,7 +14,7 @@ const { MyGroup } = require('../models/mygroup');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
async function getGroupRecAdminsInfo(idapp, data) {

View File

@@ -9,7 +9,7 @@ const Hours = require('../models/hours');
//const { ListaIngresso } = require('../models/listaingresso');
//const { Graduatoria } = require('../models/graduatoria');
// const { ExtraList } = require('../models/extralist');
const { ObjectID } = require('mongodb');
const { ObjectId } = require('mongodb');
const sendemail = require('../sendemail');
@@ -1338,7 +1338,7 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
for (let ind = 0; ind < 100; ind++) {
let myuser = new User();
myuser._id = new ObjectID();
myuser._id = new ObjectId();
myuser.index = last + ind + 1;
myuser.idapp = idapp;
myuser.password = '$2a$12$DEaX1h5saTUVC43f7kubyOAlah1xHDgqQTfSIux0.RFDT9WGbyCaG';
@@ -1552,23 +1552,34 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
} else if (mydata.dbop === 'dropProducts') {
await Product.collection.drop();
ris = await ProductInfo.collection.drop();
if (idapp) {
const deleteProducts = await Product.deleteMany({ idapp });
console.log(`Cancellati ${deleteProducts.deletedCount} record dalla collezione Product.`);
// Cancellazione dei record nella collezione ProductInfo
const deleteProductInfo = await ProductInfo.deleteMany({ idapp });
console.log(`Cancellati ${deleteProductInfo.deletedCount} record dalla collezione ProductInfo.`);
}
ris = !!deleteProductInfo;
} else if (mydata.dbop === 'dropCatProd') {
await CatProd.collection.drop();
const deleteCatProd = await CatProd.deleteMany({ idapp });
} else if (mydata.dbop === 'dropSubCatProd') {
await SubCatProd.collection.drop();
const deleteSubCatProd = await SubCatProd.deleteMany({ idapp });
} else if (mydata.dbop === 'dropAllOrders') {
try {
ris = Order.collection.drop();
ris = OrdersCart.collection.drop();
ris = Cart.collection.drop();
const deleteOrder = await Order.deleteMany({ idapp });
const deleteOrdersCart = await OrdersCart.deleteMany({ idapp });
const deleteCart = await Cart.deleteMany({ idapp });
ris = deleteCart;
} catch (e) {
console.error('Err:', e);
}
@@ -1601,7 +1612,7 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
} else if (mydata.dbop === 'dropAllCarts') {
ris = Cart.collection.drop();
ris = await Cart.deleteMany({ idapp });
} else if (mydata.dbop === 'RewriteCitiesTable') {