order
This commit is contained in:
@@ -26,6 +26,13 @@ export class OrderController {
|
||||
return this.orderService.createOrderAsUser(userId, body);
|
||||
}
|
||||
|
||||
@Get('public/order/:id')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'order detail' })
|
||||
orderDetail(@Param('id') orderId: string, @UserId() userId: string) {
|
||||
return this.orderService.getOrderAsUser(userId, orderId);
|
||||
}
|
||||
|
||||
@Delete('public/order/:id')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Delete order ' })
|
||||
|
||||
@@ -116,7 +116,6 @@ export class OrderService {
|
||||
return orderItem
|
||||
}
|
||||
|
||||
|
||||
async updateOrderItemAsUser(userId: string, orderId: string, itemId: string, dto: UpdateOrderItemDtoAsUser) {
|
||||
|
||||
const order = await this.findOrderOrFail(orderId)
|
||||
@@ -147,7 +146,6 @@ export class OrderService {
|
||||
return orderItem
|
||||
}
|
||||
|
||||
|
||||
async removeOrderItemAsAdmin(orderId: string, itemId: string) {
|
||||
|
||||
const order = await this.findOrderOrFail(orderId)
|
||||
@@ -296,6 +294,13 @@ export class OrderService {
|
||||
await this.em.flush()
|
||||
}
|
||||
|
||||
async getOrderAsUser(userId: string, orderId: string) {
|
||||
const order = await this.findOrderOrFail(orderId)
|
||||
if (order.user.id !== userId) {
|
||||
throw new BadRequestException("This order is not belongs to you")
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Entity Methods ====================
|
||||
|
||||
private async createOrderItem(order: Order, product: Product, dto: CreateOrderItemParam, em?: EntityManager) {
|
||||
|
||||
Reference in New Issue
Block a user