From b3d887ef7f35b118ba431aa3239173d135a77931 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Tue, 7 Oct 2025 16:20:22 +0330 Subject: [PATCH] add: cart shipmet methods --- src/modules/shipment/shipment.controller.ts | 10 ++++++++++ src/modules/shipment/shipment.service.ts | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/modules/shipment/shipment.controller.ts b/src/modules/shipment/shipment.controller.ts index 0c61219..5e53b3f 100644 --- a/src/modules/shipment/shipment.controller.ts +++ b/src/modules/shipment/shipment.controller.ts @@ -53,6 +53,16 @@ class ShipmentController extends BaseController { const data = await this.shipmentService.selectShipmentProvider(saveShippingInfo, user._id.toString()); return this.response(data); } + + @ApiOperation("get shipment methods for checkout") + @ApiResponse("Successful", HttpStatus.Ok) + @ApiAuth() + @httpGet("/cart", Guard.authUser()) + public async getCartShipmentMethods(@request() req: Request) { + const user = req.user as IUser; + const data = await this.shipmentService.getCartShipmentMethods(user._id.toString()); + return this.response(data); + } } export { ShipmentController }; diff --git a/src/modules/shipment/shipment.service.ts b/src/modules/shipment/shipment.service.ts index ac0435e..bd6b8da 100644 --- a/src/modules/shipment/shipment.service.ts +++ b/src/modules/shipment/shipment.service.ts @@ -270,6 +270,18 @@ class ShipmentService { }; } + async getCartShipmentMethods(userId: string) { + const cart = (await this.cartRepo.getCartWithAggregate(userId))[0] as ICart; + + if (!cart) throw new BadRequestError(CartMessage.CartNotFound); + + const { shipping: ShipmentMethods } = await this.calculateAllShipmentOptions(userId); + + if (!ShipmentMethods.length) throw new BadRequestError(SetShipmentMessage.ShipmentOptionsUnavailable); + + return { ShipmentMethods }; + } + //===============================> helper method // Helper function to calculate shipping days range private calculateShippingDays(deliveryType: DeliveryType, deliveryTime: number): string[] {