Merge pull request #11 from Danakcorp/mrtz

add: cart shipmet methods
This commit is contained in:
morteza-mortezai
2025-10-07 16:20:51 +03:30
committed by GitHub
2 changed files with 22 additions and 0 deletions
@@ -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 };
+12
View File
@@ -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[] {