confirm order item
This commit is contained in:
@@ -28,24 +28,15 @@ export class OrdersController {
|
|||||||
|
|
||||||
@Get('public/orders')
|
@Get('public/orders')
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
|
||||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
|
||||||
@ApiQuery({ name: 'search', required: false, type: String })
|
|
||||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
|
||||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
|
||||||
@ApiQuery({ name: 'statuses', required: false, enum: OrderStatusEnum })
|
|
||||||
@ApiQuery({ name: 'from', required: false, type: Date })
|
|
||||||
@ApiQuery({ name: 'to', required: false, type: Date })
|
|
||||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||||
async findAll(@Query() dto: FindOrdersDto, @UserId() userId: string) {
|
async findAll(@Query() dto: FindOrdersDto, @UserId() userId: string) {
|
||||||
const orders = await this.ordersService.findAllForUser(userId, dto);
|
const orders = await this.ordersService.findAllForUser(userId, dto);
|
||||||
return orders
|
return orders
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('admin/orders/:orderId/create-invoice')
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@ApiOperation({ summary: 'Create invoice for new order' })
|
@ApiOperation({ summary: 'Create invoice for new order' })
|
||||||
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
|
||||||
@Post('admin/orders/:orderId/create-invoice')
|
|
||||||
createInvoice(@Param('orderId') orderId: string, @Body() body: CreateInvoiceDto) {
|
createInvoice(@Param('orderId') orderId: string, @Body() body: CreateInvoiceDto) {
|
||||||
return this.ordersService.createInvoice(orderId, body);
|
return this.ordersService.createInvoice(orderId, body);
|
||||||
}
|
}
|
||||||
@@ -58,17 +49,16 @@ export class OrdersController {
|
|||||||
// enum: OrderStatus,
|
// enum: OrderStatus,
|
||||||
// })
|
// })
|
||||||
|
|
||||||
// @ApiBody({ type: UpdateOrderStatusDto })
|
@Post('admin/orders/:orderId/items/:orderItemId')
|
||||||
// @ApiOperation({ summary: 'Update status of an order By User' })
|
@UseGuards(AuthGuard)
|
||||||
// @ApiParam({ name: 'id', description: 'Order ID' })
|
@ApiOperation({ summary: 'Confirm Invoice Item By User' })
|
||||||
// cancelOrder(
|
confirmOrderItem(
|
||||||
// @Body() dto: UpdateOrderStatusDto,
|
@Param('orderId') orderId: string,
|
||||||
// @Param('id') orderId: string,
|
@Param('orderItemId') orderItemId: string,
|
||||||
// @Param('status') status: OrderStatus,
|
@UserId() userId: string
|
||||||
// ,
|
) {
|
||||||
// ) {
|
return this.ordersService.confirmOrderItem(userId, orderId, +orderItemId);
|
||||||
// return this.ordersService.changeOrderStatus(orderId, , status, 'user', dto?.desc);
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// /******************** Admin Routes **********************/
|
// /******************** Admin Routes **********************/
|
||||||
// @UseGuards(AdminAuthGuard)
|
// @UseGuards(AdminAuthGuard)
|
||||||
|
|||||||
@@ -165,4 +165,24 @@ export class OrdersService {
|
|||||||
|
|
||||||
return order
|
return order
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async confirmOrderItem(userId: string, orderId: string, orderItemId: number) {
|
||||||
|
|
||||||
|
const orderItem = await this.orderItemRepository.findOne({ id: orderItemId, order: { id: orderId } },
|
||||||
|
{ populate: ['order', 'order.user'] })
|
||||||
|
|
||||||
|
if (!orderItem) {
|
||||||
|
throw new BadRequestException("Order Item not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orderItem.order.user.id !== userId) {
|
||||||
|
throw new BadRequestException("Order Item does not belong to you")
|
||||||
|
}
|
||||||
|
|
||||||
|
orderItem.status=OrderItemStatus.CONFIRMED
|
||||||
|
|
||||||
|
this.em.persistAndFlush(OrderItem)
|
||||||
|
|
||||||
|
return orderItem
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user