Skip to content

Commit

Permalink
FES-27-get-cart-info (#35)
Browse files Browse the repository at this point in the history
* add controller and response DTO
Co-authored-by: NHT <[email protected]>
  • Loading branch information
nfesta2023 authored Jan 11, 2024
1 parent 2d5e9ce commit 238807f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/feature/cart/cart.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { FlagsmithService } from 'src/dependency/flagsmith/flagsmith.service';
import { MessagePattern } from '@nestjs/microservices';
import { AddToCartRequest } from './dto/add-to-cart-request.dto';
import { AddToCartResponse } from './dto/add-to-cart-response.dto';
import { GetCartDetailResponse } from './dto/get-cart-detail-response.dto';
import { CartItem } from 'src/entity/cart-item.entity';

@Controller()
export class CartController {
Expand Down Expand Up @@ -53,4 +55,35 @@ export class CartController {
return res;
}
}

@MessagePattern({ cmd: 'get_cart_detail' })
async getCartDetail(customer_id: number): Promise<GetCartDetailResponse> {
if (this.flagService.isFeatureEnabled('fes-27-get-cart-info')) {
const res = new GetCartDetailResponse(200, '');

try {
const cartItems: CartItem[] =
await this.cartService.getCart(customer_id);
res.statusCode = 200;
res.message = 'Get cart detail successfully';
res.data = {
customer_id: customer_id,
cart_info: cartItems,
};
} catch (error) {
if (error instanceof HttpException) {
res.statusCode = error.getStatus();
res.message = error.getResponse();
res.data = null;
} else {
res.statusCode = 500;
res.message = error.toString();
res.data = null;
}
return res;
}

return res;
}
}
}
25 changes: 25 additions & 0 deletions src/feature/cart/dto/get-cart-detail-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { GeneralResponse } from 'src/dto/general-response.dto';

export class GetCartDetailResponse extends GeneralResponse {
data: CartDetail;
}

interface CartDetail {
customer_id: number;
cart_info: CartItem[];
}

interface CartItem {
item_id: number;
sku_id: number;
customer_id: number;
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;
created_at: Date;
}

0 comments on commit 238807f

Please sign in to comment.