- corretta configurazione
- fix problemi al database su piuchebuono una chiamata dava errore...
const c = ....
if (mycart && mycart.length > 0) {
This commit is contained in:
@@ -46,8 +46,10 @@ const database = process.env.DATABASE || "test"; // Nome del database, default a
|
||||
if (process.env.AUTH_DB_PASSING === "1") {
|
||||
// replace username and password in the process.env.DOMAIN
|
||||
process.env.MONGODB_URI = process.env.DOMAIN_AUTH.replace('{username}', username).replace('{password}', password) + database;
|
||||
process.env.MONGODB_URI_NOPWD = process.env.DOMAIN_AUTH.replace('{username}', username) + database;
|
||||
} else {
|
||||
process.env.MONGODB_URI = domain + database;
|
||||
process.env.MONGODB_URI_NOPWD = domain + database;
|
||||
}
|
||||
|
||||
console.log('process.env.MONGODB_URI:', process.env.MONGODB_URI);
|
||||
console.log('process.env.MONGODB_URI:', process.env.MONGODB_URI_NOPWD);
|
||||
|
||||
@@ -41,7 +41,7 @@ console.log('Mongoose Version ' + mongoose.version);
|
||||
|
||||
// URL di connessione
|
||||
const connectionUrl = process.env.MONGODB_URI;
|
||||
console.log('Connessione a ' + connectionUrl + ' in corso...');
|
||||
console.log('Connessione a ' + process.env.MONGODB_URI_NOPWD + ' in corso...');
|
||||
|
||||
// Funzione per connettersi al database con retry
|
||||
async function connectToDatabase(uri, opts) {
|
||||
@@ -52,12 +52,12 @@ async function connectToDatabase(uri, opts) {
|
||||
console.log("Sto provando a connettermi al database...");
|
||||
await mongoose.connect(uri);
|
||||
|
||||
console.log(' *** CONNESSIONE EFFETTUATA ! ' + uri + ' db: ' + process.env.DATABASE);
|
||||
console.log(' *** CONNESSIONE EFFETTUATA ! ' + ' db: ' + process.env.DATABASE);
|
||||
|
||||
console.log(' Database corrente:', mongoose.connection.name);
|
||||
|
||||
// Ottieni l'URL completo della connessione
|
||||
console.log(' URL di connessione:', mongoose.connection.client.s.url);
|
||||
// console.log(' URL di connessione:', mongoose.connection.client.s.url);
|
||||
|
||||
const db = mongoose.connection;
|
||||
const serverInfo = await db.db.admin().serverStatus(); // Ottieni lo stato del server
|
||||
|
||||
@@ -548,41 +548,47 @@ module.exports.updateOrdersCartById = async function(id, newOrdersCart, callback
|
||||
id,
|
||||
deleted: false,
|
||||
}
|
||||
let mycart = null;
|
||||
try {
|
||||
const c = await OrdersCart.find(query);
|
||||
mycart = await OrdersCart.find(query);
|
||||
} catch (err) {
|
||||
console.log('ERR: updateOrdersCartById', err);
|
||||
if (err) throw err;
|
||||
}
|
||||
|
||||
//exist cart in databse
|
||||
if (c.length > 0) {
|
||||
return OrdersCart.findOneAndUpdate(
|
||||
{ _id: id },
|
||||
{
|
||||
$set: {
|
||||
items: newOrdersCart.items,
|
||||
totalQty: newOrdersCart.totalQty,
|
||||
totalQtyPreordered: newOrdersCart.totalQtyPreordered,
|
||||
totalPrice: newOrdersCart.totalPrice,
|
||||
totalPriceCalc: newOrdersCart.totalPriceCalc ? newOrdersCart.totalPriceCalc : newOrdersCart.totalPrice,
|
||||
userId: userId,
|
||||
status: newOrdersCart.status,
|
||||
numorder: newOrdersCart.numorder,
|
||||
numord_pers: newOrdersCart.numord_pers,
|
||||
note: newOrdersCart.note,
|
||||
modify_at: new Date(),
|
||||
}
|
||||
},
|
||||
{ new: true },
|
||||
callback
|
||||
)
|
||||
} else {
|
||||
//no cart in database
|
||||
return newOrdersCart.save(callback)
|
||||
try {
|
||||
//exist cart in databse
|
||||
if (mycart && mycart.length > 0) {
|
||||
return OrdersCart.findOneAndUpdate(
|
||||
{ _id: id },
|
||||
{
|
||||
$set: {
|
||||
items: newOrdersCart.items,
|
||||
totalQty: newOrdersCart.totalQty,
|
||||
totalQtyPreordered: newOrdersCart.totalQtyPreordered,
|
||||
totalPrice: newOrdersCart.totalPrice,
|
||||
totalPriceCalc: newOrdersCart.totalPriceCalc ? newOrdersCart.totalPriceCalc : newOrdersCart.totalPrice,
|
||||
userId: userId,
|
||||
status: newOrdersCart.status,
|
||||
numorder: newOrdersCart.numorder,
|
||||
numord_pers: newOrdersCart.numord_pers,
|
||||
note: newOrdersCart.note,
|
||||
modify_at: new Date(),
|
||||
}
|
||||
},
|
||||
{ new: true },
|
||||
callback
|
||||
)
|
||||
} else {
|
||||
//no cart in database
|
||||
return newOrdersCart.save(callback)
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Err updateOrdersCartById', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports.setFieldInOrdersById = async function (objtoset, myOrderCart) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -248,7 +248,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
let options = req.body.options;
|
||||
|
||||
try {
|
||||
let mycart = await Cart.findOne({ _id: cart_id });
|
||||
let mycart = await Cart.findOne({ _id: cart_id }).lean();
|
||||
|
||||
if (!mycart) {
|
||||
return res.send({
|
||||
@@ -309,19 +309,21 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
.then(async (orders) => {
|
||||
if (!!orders) {
|
||||
|
||||
await OrdersCart.updateCmd(orders[0], status, true, req, options);
|
||||
if (orders[0]) {
|
||||
await OrdersCart.updateCmd(orders[0], status, true, req, options);
|
||||
|
||||
// Invia la email dell'Ordine
|
||||
sendemail.sendEmail_OrderProduct(userDest.lang, idapp, orders[0], userDest)
|
||||
.then(async (ris) => {
|
||||
myorderCart = await OrdersCart.findById(idordercart).lean();
|
||||
return res.send({
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
status: myris.status,
|
||||
orders: orders,
|
||||
recOrderCart: myorderCart
|
||||
// Invia la email dell'Ordine
|
||||
sendemail.sendEmail_OrderProduct(userDest.lang, idapp, orders[0], userDest)
|
||||
.then(async (ris) => {
|
||||
myorderCart = await OrdersCart.findById(idordercart).lean();
|
||||
return res.send({
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
status: myris.status,
|
||||
orders: orders,
|
||||
recOrderCart: myorderCart
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@@ -1961,22 +1961,22 @@ function load(req, res, version) {
|
||||
operators,
|
||||
wheres,
|
||||
contribtype,
|
||||
settings,
|
||||
settings, // 5
|
||||
permissions,
|
||||
disciplines,
|
||||
newstosent,
|
||||
mailinglist,
|
||||
mypage,
|
||||
mypage, // 10
|
||||
gallery,
|
||||
paymenttype,
|
||||
calcstat,
|
||||
calzoom,
|
||||
producers,
|
||||
producers, // 15
|
||||
cart,
|
||||
storehouses,
|
||||
departments,
|
||||
orderscart,
|
||||
groups,
|
||||
groups, // 20
|
||||
resps,
|
||||
workers,
|
||||
internalpages,
|
||||
|
||||
Reference in New Issue
Block a user