From 54f18dc31d317f53a0e49d16021e08d74a4a0b9f Mon Sep 17 00:00:00 2001 From: nfesta2023 <142601504+nfesta2023@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:23:16 +0700 Subject: [PATCH] update cart return info (#76) Co-authored-by: NHT --- src/feature/cart/cart.service.ts | 2 + .../cart/dto/add-to-cart-response.dto.ts | 41 +------------------ .../cart/dto/delete-cart-item-response.dto.ts | 40 +----------------- .../cart/dto/get-cart-detail-response.dto.ts | 2 + .../dto/quick-add-to-cart-response.dto.ts | 41 +------------------ .../dto/update-cart-advanced-response.dto.ts | 41 +------------------ .../dto/update-cart-basic-response.dto.ts | 41 +------------------ src/feature/common/common.service.ts | 2 + src/type/index.ts | 4 ++ 9 files changed, 20 insertions(+), 194 deletions(-) diff --git a/src/feature/cart/cart.service.ts b/src/feature/cart/cart.service.ts index 4065036..e34d512 100644 --- a/src/feature/cart/cart.service.ts +++ b/src/feature/cart/cart.service.ts @@ -229,6 +229,8 @@ export class CartService { item_img: additionalInfoForSku.sku_img, customer_id: item.customer_id, sku_id: item.sku_id, + menu_item_id: additionalInfoForSku.menu_item_id, + quantity_available: additionalInfoForSku.quantity_available, price: additionalInfoForSku.sku_price, price_after_discount: additionalInfoForSku.sku_price_after_discount, unit: additionalInfoForSku.sku_unit, diff --git a/src/feature/cart/dto/add-to-cart-response.dto.ts b/src/feature/cart/dto/add-to-cart-response.dto.ts index 1134a37..7b61308 100644 --- a/src/feature/cart/dto/add-to-cart-response.dto.ts +++ b/src/feature/cart/dto/add-to-cart-response.dto.ts @@ -1,40 +1,3 @@ -import { GeneralResponse } from 'src/dto/general-response.dto'; -import { TextByLang } from 'src/type'; +import { GetCartDetailResponse } from './get-cart-detail-response.dto'; -export class AddToCartResponse extends GeneralResponse { - data: AddToCartResponseData; -} - -interface AddToCartResponseData { - customer_id: number; - restaurant_id: number; - restaurant_name: TextByLang[]; - restaurant_logo_img: string; - cart_info: FullCartItem[]; -} - -interface FullCartItem { - item_id: number; - item_name: TextByLang[]; - item_img: string; - customer_id: number; - sku_id: number; - price: number; - price_after_discount: number; - unit: string; - qty_ordered: number; - advanced_taste_customization: string; - basic_taste_customization: string; - portion_customization: string; - advanced_taste_customization_obj: string; - basic_taste_customization_obj: string; - notes: string; - restaurant_id: number; - packaging_info: CartPackagingInfo; -} - -interface CartPackagingInfo { - packaging_id: number; - name: TextByLang[]; - price: number; -} +export class AddToCartResponse extends GetCartDetailResponse {} diff --git a/src/feature/cart/dto/delete-cart-item-response.dto.ts b/src/feature/cart/dto/delete-cart-item-response.dto.ts index 1d66e8e..3ce8545 100644 --- a/src/feature/cart/dto/delete-cart-item-response.dto.ts +++ b/src/feature/cart/dto/delete-cart-item-response.dto.ts @@ -1,39 +1,3 @@ -import { GeneralResponse } from 'src/dto/general-response.dto'; -import { TextByLang } from 'src/type'; +import { GetCartDetailResponse } from './get-cart-detail-response.dto'; -export class DeleteCartItemResponse extends GeneralResponse { - data: Data; -} -interface Data { - customer_id: number; - restaurant_id: number; - restaurant_name: TextByLang[]; - restaurant_logo_img: string; - cart_info: FullCartItem[]; -} - -interface FullCartItem { - item_id: number; - item_name: TextByLang[]; - item_img: string; - customer_id: number; - sku_id: number; - price: number; - price_after_discount: number; - unit: string; - qty_ordered: number; - advanced_taste_customization: string; - basic_taste_customization: string; - portion_customization: string; - advanced_taste_customization_obj: string; - basic_taste_customization_obj: string; - notes: string; - restaurant_id: number; - packaging_info: CartPackagingInfo; -} - -interface CartPackagingInfo { - packaging_id: number; - name: TextByLang[]; - price: number; -} +export class DeleteCartItemResponse extends GetCartDetailResponse {} diff --git a/src/feature/cart/dto/get-cart-detail-response.dto.ts b/src/feature/cart/dto/get-cart-detail-response.dto.ts index 3080dd0..93ed31e 100644 --- a/src/feature/cart/dto/get-cart-detail-response.dto.ts +++ b/src/feature/cart/dto/get-cart-detail-response.dto.ts @@ -19,6 +19,8 @@ interface FullCartItem { item_img: string; customer_id: number; sku_id: number; + menu_item_id: number; + quantity_available: number; price: number; price_after_discount: number; unit: string; diff --git a/src/feature/cart/dto/quick-add-to-cart-response.dto.ts b/src/feature/cart/dto/quick-add-to-cart-response.dto.ts index 475fa71..e1f8537 100644 --- a/src/feature/cart/dto/quick-add-to-cart-response.dto.ts +++ b/src/feature/cart/dto/quick-add-to-cart-response.dto.ts @@ -1,40 +1,3 @@ -import { GeneralResponse } from 'src/dto/general-response.dto'; -import { TextByLang } from 'src/type'; +import { GetCartDetailResponse } from './get-cart-detail-response.dto'; -export class QuickAddToCartResponse extends GeneralResponse { - data: QuickAddToCartResponseData; -} - -interface QuickAddToCartResponseData { - customer_id: number; - restaurant_id: number; - restaurant_name: TextByLang[]; - restaurant_logo_img: string; - cart_info: FullCartItem[]; -} - -interface FullCartItem { - item_id: number; - item_name: TextByLang[]; - item_img: string; - customer_id: number; - sku_id: number; - price: number; - price_after_discount: number; - unit: string; - qty_ordered: number; - advanced_taste_customization: string; - basic_taste_customization: string; - portion_customization: string; - advanced_taste_customization_obj: string; - basic_taste_customization_obj: string; - notes: string; - restaurant_id: number; - packaging_info: CartPackagingInfo; -} - -interface CartPackagingInfo { - packaging_id: number; - name: TextByLang[]; - price: number; -} +export class QuickAddToCartResponse extends GetCartDetailResponse {} diff --git a/src/feature/cart/dto/update-cart-advanced-response.dto.ts b/src/feature/cart/dto/update-cart-advanced-response.dto.ts index 272ca5d..aa29da0 100644 --- a/src/feature/cart/dto/update-cart-advanced-response.dto.ts +++ b/src/feature/cart/dto/update-cart-advanced-response.dto.ts @@ -1,40 +1,3 @@ -import { GeneralResponse } from 'src/dto/general-response.dto'; -import { TextByLang } from 'src/type'; +import { GetCartDetailResponse } from './get-cart-detail-response.dto'; -export class UpdateCartAdvancedResponse extends GeneralResponse { - data: CartDetail; -} - -interface CartDetail { - customer_id: number; - restaurant_id: number; - restaurant_name: TextByLang[]; - restaurant_logo_img: string; - cart_info: FullCartItem[]; -} - -interface FullCartItem { - item_id: number; - item_name: TextByLang[]; - item_img: string; - customer_id: number; - sku_id: number; - price: number; - price_after_discount: number; - unit: string; - qty_ordered: number; - advanced_taste_customization: string; - basic_taste_customization: string; - portion_customization: string; - advanced_taste_customization_obj: string; - basic_taste_customization_obj: string; - notes: string; - restaurant_id: number; - packaging_info: CartPackagingInfo; -} - -interface CartPackagingInfo { - packaging_id: number; - name: TextByLang[]; - price: number; -} +export class UpdateCartAdvancedResponse extends GetCartDetailResponse {} diff --git a/src/feature/cart/dto/update-cart-basic-response.dto.ts b/src/feature/cart/dto/update-cart-basic-response.dto.ts index 88d7f35..b14ffb6 100644 --- a/src/feature/cart/dto/update-cart-basic-response.dto.ts +++ b/src/feature/cart/dto/update-cart-basic-response.dto.ts @@ -1,40 +1,3 @@ -import { GeneralResponse } from 'src/dto/general-response.dto'; -import { TextByLang } from 'src/type'; +import { GetCartDetailResponse } from './get-cart-detail-response.dto'; -export class UpdateCartBasicResponse extends GeneralResponse { - data: CartDetail; -} - -interface CartDetail { - customer_id: number; - restaurant_id: number; - restaurant_name: TextByLang[]; - restaurant_logo_img: string; - cart_info: FullCartItem[]; -} - -interface FullCartItem { - item_id: number; - item_name: TextByLang[]; - item_img: string; - customer_id: number; - sku_id: number; - price: number; - price_after_discount: number; - unit: string; - qty_ordered: number; - advanced_taste_customization: string; - basic_taste_customization: string; - portion_customization: string; - advanced_taste_customization_obj: string; - basic_taste_customization_obj: string; - notes: string; - restaurant_id: number; - packaging_info: CartPackagingInfo; -} - -interface CartPackagingInfo { - packaging_id: number; - name: TextByLang[]; - price: number; -} +export class UpdateCartBasicResponse extends GetCartDetailResponse {} diff --git a/src/feature/common/common.service.ts b/src/feature/common/common.service.ts index 47ff342..7693079 100644 --- a/src/feature/common/common.service.ts +++ b/src/feature/common/common.service.ts @@ -771,6 +771,8 @@ export class CommonService { sku_price: item.price, sku_price_after_discount: await this.getAvailableDiscountPrice(item), sku_unit: priceUnit?.price_unit || null, + menu_item_id: item.menu_item_id, + quantity_available: item.menu_item.quantity_available, }; data.push(additionalInfoForSKU); } diff --git a/src/type/index.ts b/src/type/index.ts index 8d760bd..4e1e403 100644 --- a/src/type/index.ts +++ b/src/type/index.ts @@ -148,6 +148,8 @@ export interface FullCartItem { item_img: string; customer_id: number; sku_id: number; + menu_item_id: number; + quantity_available: number; price: number; price_after_discount: number; unit: string; @@ -175,6 +177,8 @@ export interface AdditionalInfoForSKU { sku_price: number; sku_price_after_discount: number; sku_unit: string; + menu_item_id: number; + quantity_available: number; } export interface PriceUnitByMenuItem { menu_item_id: number;