- Aggiornato node.js alla versione 22.18.1

- Aggiornato tutti i pacchetti del server all'ultima versione.
- passato mongoose da versione 5 a versione 6
This commit is contained in:
Surya Paolo
2025-03-03 00:46:08 +01:00
parent 45d06b0923
commit 53a70a1c96
120 changed files with 3385 additions and 6065 deletions

View File

@@ -55,7 +55,7 @@ module.exports.getCartByUserId = async function (uid, idapp) {
if (!!mycart) {
for (const idkey in mycart.items) {
try {
try {
let idorder = mycart.items[idkey]._id.toString();
let myorder = mycart.items[idkey].order;
if (!!myorder) {
@@ -89,32 +89,35 @@ module.exports.getCartByUserId = async function (uid, idapp) {
};
module.exports.updateCartByUserId = function (userId, newCart, callback) {
module.exports.updateCartByUserId = async function (userId, newCart, callback) {
let query = { userId: userId };
Cart.find(query, function (err, c) {
try {
const c = await Cart.find(query);
} catch (err) {
if (err) throw err;
}
//exist cart in databse
if (c.length > 0) {
Cart.findOneAndUpdate(
{ userId: userId },
{
$set: {
items: newCart.items,
totalQty: newCart.totalQty,
totalPrice: newCart.totalPrice,
totalPriceCalc: newCart.totalPriceCalc,
userId: userId,
},
//exist cart in databse
if (c.length > 0) {
Cart.findOneAndUpdate(
{ userId: userId },
{
$set: {
items: newCart.items,
totalQty: newCart.totalQty,
totalPrice: newCart.totalPrice,
totalPriceCalc: newCart.totalPriceCalc,
userId: userId,
},
{ new: true },
callback,
);
} else {
//no cart in database
newCart.save(callback);
}
});
},
{ new: true },
callback,
);
} else {
//no cart in database
newCart.save(callback);
}
};
module.exports.updateCartByCartId = async function (cartId, newCart) {
@@ -148,7 +151,7 @@ module.exports.updateCartByCartId = async function (cartId, newCart) {
};
module.exports.deleteCartByCartId = async function (cartId) {
return await Cart.remove({ _id: cartId });
return await Cart.deleteOne({ _id: cartId });
};
module.exports.createCart = async function (newCart) {
@@ -156,6 +159,7 @@ module.exports.createCart = async function (newCart) {
};
Cart.createIndexes((err) => {
if (err) throw err;
});
Cart.createIndexes()
.then(() => { })
.catch((err) => { throw err; });