- 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:
@@ -198,7 +198,7 @@ module.exports.getRecCartByUserId = async function (uid, idapp, numorder) {
|
||||
|
||||
module.exports.getOrdersCartById = async function (id) {
|
||||
|
||||
let query = { _id: ObjectId(id) };
|
||||
let query = { _id: new ObjectId(id) };
|
||||
|
||||
const arrris = await OrdersCart.getOrdersCartByQuery(query);
|
||||
let myrec = arrris && arrris.length > 0 ? arrris[0] : null;
|
||||
@@ -543,41 +543,44 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder, fil
|
||||
}
|
||||
|
||||
|
||||
module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
module.exports.updateOrdersCartById = async function(id, newOrdersCart, callback) {
|
||||
let query = {
|
||||
id,
|
||||
deleted: false,
|
||||
}
|
||||
OrdersCart.find(query, function (err, c) {
|
||||
if (err) throw err
|
||||
try {
|
||||
const c = 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)
|
||||
}
|
||||
})
|
||||
//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)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.setFieldInOrdersById = async function (objtoset, myOrderCart) {
|
||||
@@ -616,10 +619,10 @@ module.exports.deleteRecsInOrdersById = async function (myOrderCart) {
|
||||
let ris2 = null;
|
||||
// Imposta su tutti i singoli prodotti ordinati (Order)
|
||||
for (const recitem of myOrderCart.items) {
|
||||
ris2 = await Order.findOneAndRemove({ _id: recitem.order._id })
|
||||
ris2 = await Order.findOneAndDelete({ _id: recitem.order._id })
|
||||
}
|
||||
|
||||
const ris = await OrdersCart.findOneAndRemove({ _id: myOrderCart._id })
|
||||
const ris = await OrdersCart.findOneAndDelete({ _id: myOrderCart._id })
|
||||
|
||||
} catch (e) {
|
||||
console.log('Err', e);
|
||||
@@ -1045,19 +1048,6 @@ OrdersCartSchema.pre('save', async function (next) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (user.isModified('password')) {
|
||||
bcrypt.genSalt(10, (err, salt) => {
|
||||
bcrypt.hash(user.password, salt, (err, hash) => {
|
||||
user.password = hash;
|
||||
next();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
*/
|
||||
|
||||
next();
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
@@ -1171,6 +1161,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.createIndexes((err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
module.exports.createIndexes()
|
||||
.then(() => { })
|
||||
.catch((err) => { throw err; });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user