chore: fix problem of transcation beeing commited throw update the "

category variant
This commit is contained in:
mahyargdz
2025-09-21 11:45:24 +03:30
parent 3d1aa01f2e
commit 79f597cc90
23 changed files with 52 additions and 97 deletions
-9
View File
@@ -80,7 +80,6 @@ class ShipmentService {
// get the cart for the user
const cart = await this.cartRepo.getCartWithPopulate(userId);
if (!cart) throw new BadRequestError(CartMessage.CartNotFound);
console.log({ cart });
const shipping = [];
const cartItems = cart.items as unknown as Items[];
@@ -97,11 +96,9 @@ class ShipmentService {
});
return acc;
}, {});
console.log({ itemsByShop });
// iterate through each shops items
for (const [shopId, items] of Object.entries(itemsByShop)) {
const shop = await this.shopRepo.model.findById(shopId).lean();
console.log(shop);
if (!shop) {
continue;
}
@@ -111,9 +108,7 @@ class ShipmentService {
// for each shop, check all available shippers
for (const shipperId of shop.shipmentMethod) {
const shipmentProvider = await this.shipmentRepo.model.findById(shipperId).lean();
console.log({ shipmentProvider });
if (!shipmentProvider) {
console.log("Shipment provider not found for shipper ID:", shipperId);
continue;
}
@@ -165,7 +160,6 @@ class ShipmentService {
items,
shippers: shopShippers,
});
console.log({ shipping });
}
return { shipping: shipping.map((ship) => ShippingOptionDTO.transformShipment(ship)) };
@@ -327,12 +321,9 @@ class ShipmentService {
// Helper function to calculate the shipping cost for a product variant based on shipment provider
private async calculateShippingCost(shipmentProvider: IShipmentProviders, package_weight: number, quantity: number): Promise<number> {
console.log({ package_weight });
console.dir({ shipmentProvider: shipmentProvider.costs }, { depth: null });
const cost = shipmentProvider.costs.find(
(cost) => package_weight / 1000 >= cost.weightRange.min && package_weight / 1000 <= cost.weightRange.max,
);
console.log({ cost });
// if (!cost) throw new BadRequestError("No shipping cost available for this weight range");
const defaulCost = cost ?? { cost_first: 100_000, cost_rest: 10_000 };