From 750a60f954e3e6df19e8904b9f32510a01aafbeb Mon Sep 17 00:00:00 2001 From: nfesta2023 <142601504+nfesta2023@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:43:38 +0700 Subject: [PATCH] add payment info to order history by restaurant (#100) Co-authored-by: NHT --- .../get-order-history-by-restaurant-response.dto.ts | 5 +++++ src/feature/order/order.service.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/feature/order/dto/get-order-history-by-restaurant-response.dto.ts b/src/feature/order/dto/get-order-history-by-restaurant-response.dto.ts index 775497c..c8d0947 100644 --- a/src/feature/order/dto/get-order-history-by-restaurant-response.dto.ts +++ b/src/feature/order/dto/get-order-history-by-restaurant-response.dto.ts @@ -14,6 +14,7 @@ export interface HistoricalOrderByRestaurant { order_items: OrderItem[]; order_total: number; order_score: number; + payment_method: Payment; } interface OrderStatusLog { @@ -53,3 +54,7 @@ interface OptionSelection { interface BasicTasteSelection { no_adding_id: string; } +interface Payment { + id: number; + name: string; +} diff --git a/src/feature/order/order.service.ts b/src/feature/order/order.service.ts index 5c6b1b3..3db379c 100644 --- a/src/feature/order/order.service.ts +++ b/src/feature/order/order.service.ts @@ -2110,7 +2110,13 @@ export class OrderService { await this.getFoodRatingsWithOrderSkuIds( orderItems.map((i) => i.order_sku_id), ); - this.logger.log(foodRatings); + + //Get invoice + const invoice = await this.entityManager + .createQueryBuilder(Invoice, 'invoice') + .leftJoinAndSelect('invoice.payment_option_obj', 'paymentOption') + .where('invoice.order_id = :order_id', { order_id: order.order_id }) + .getOne(); //Build output const historicalOrderInfo: HistoricalOrderByRestaurant = { @@ -2123,6 +2129,10 @@ export class OrderService { foodRatings .map((i) => i.score) .reduce((sum, val) => (sum += val), 0) / foodRatings.length, + payment_method: { + id: invoice?.payment_option_obj.option_id, + name: invoice?.payment_option_obj.name, + }, }; order.order_status_log.forEach((log) => {