Skip to content

Commit

Permalink
fes-36-delete-whole-cart (#41)
Browse files Browse the repository at this point in the history
* add logic to delete the whole cart
Co-authored-by: NHT <[email protected]>
  • Loading branch information
nfesta2023 authored Jan 25, 2024
1 parent 0ca54cc commit e68fc34
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/feature/cart/cart.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { GetCartDetailResponse } from './dto/get-cart-detail-response.dto';
import { CartItem } from 'src/entity/cart-item.entity';
import { UpdateCartBasicRequest } from './dto/update-cart-basic-request.dto';
import { UpdateCartBasicResponse } from './dto/update-cart-basic-response.dto';
import { GeneralResponse } from 'src/dto/general-response.dto';

@Controller()
export class CartController {
Expand Down Expand Up @@ -175,4 +176,29 @@ export class CartController {
return res;
}
}

@MessagePattern({ cmd: 'delete_all_cart_item' })
async deleteAllCartItem(customer_id: number): Promise<GeneralResponse> {
if (this.flagService.isFeatureEnabled('fes-36-delete-whole-cart')) {
const res = new GeneralResponse(200, '');
try {
await this.cartService.deleteAllCartItem(customer_id);
res.statusCode = 200;
res.message = 'Delete all cart items successfully';
res.data = null;
} 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;
}
}
}
11 changes: 11 additions & 0 deletions src/feature/cart/cart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,15 @@ export class CartService {
);
}
}

async deleteAllCartItem(customer_id: number) {
if (this.flagService.isFeatureEnabled('fes-36-delete-whole-cart')) {
await this.entityManager
.createQueryBuilder()
.delete()
.from(CartItem)
.where('customer_id = :customer_id', { customer_id })
.execute();
}
}
}

0 comments on commit e68fc34

Please sign in to comment.