Corretto incongruenze OrdersCart

This commit is contained in:
Surya Paolo
2023-12-21 01:34:33 +01:00
parent 7af909d2be
commit 2ab4bd4e2a
4 changed files with 110 additions and 18 deletions

View File

@@ -6,18 +6,25 @@ const { ObjectID } = require('mongodb');
const Order = require('../models/order');
class Cart {
constructor(order) {
this.items = {};
if (!!order) {
this.idapp = order.idapp || 0;
this.items[order._id] = order;
this.userId = order.userId || "";
}
constructor(order, arrorders) {
this.modify_at = new Date();
this.items = {};
if (!!order) {
this.initializeFromOrder(order);
} else if (!!arrorders) {
for (const ord of arrorders) {
this.items.push(ord)
}
}
this.updatetotals();
}
initializeFromOrder(order) {
this.idapp = order.idapp || 0;
this.userId = order.userId || "";
this.items[order._id] = order;
}
static constructByCart(cart) {
try {
const mynewcart = new Cart(null);
@@ -117,7 +124,7 @@ class Cart {
} catch (e) {
console.error('Err', e);
}
return null;
return null;
}
updatetotals() {