This commit is contained in:
2025-12-06 11:00:25 +03:30
parent 297e23e164
commit 69e27aa7f6
2 changed files with 39 additions and 20 deletions
+19 -10
View File
@@ -33,8 +33,8 @@ export class OrdersController {
@ApiOperation({ summary: 'Get an order By id for User' }) @ApiOperation({ summary: 'Get an order By id for User' })
@ApiParam({ name: 'orderId', description: 'Order ID' }) @ApiParam({ name: 'orderId', description: 'Order ID' })
@Get('public/orders/:orderId') @Get('public/orders/:orderId')
findOne(@Param('orderId') orderId: string) { findOne(@Param('orderId') orderId: string, @RestId() restId: string) {
return this.ordersService.findOne(orderId); return this.ordersService.findOne(orderId, restId);
} }
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@@ -42,8 +42,8 @@ export class OrdersController {
@Patch('public/orders/:id/cancel') @Patch('public/orders/:id/cancel')
@ApiOperation({ summary: 'Cancel an order By User' }) @ApiOperation({ summary: 'Cancel an order By User' })
@ApiParam({ name: 'id', description: 'Order ID' }) @ApiParam({ name: 'id', description: 'Order ID' })
cancelOrder(@Param('id') id: string) { cancelOrder(@Param('id') id: string, @RestId() restId: string) {
return this.ordersService.cancelOrder(id); return this.ordersService.cancelOrder(id, restId);
} }
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@@ -59,8 +59,17 @@ export class OrdersController {
@Patch('admin/orders/:orderId/confirm') @Patch('admin/orders/:orderId/confirm')
@ApiOperation({ summary: 'Accept an order' }) @ApiOperation({ summary: 'Accept an order' })
@ApiParam({ name: 'orderId', description: 'Order ID' }) @ApiParam({ name: 'orderId', description: 'Order ID' })
acceptOrder(@Param('orderId') orderId: string) { acceptOrder(@Param('orderId') orderId: string, @RestId() restId: string) {
return this.ordersService.acceptOrder(orderId); return this.ordersService.acceptOrder(orderId, restId);
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Patch('admin/orders/:id/prepare')
@ApiOperation({ summary: 'Prepare an order By Admin' })
@ApiParam({ name: 'id', description: 'Order ID' })
prepareOrder(@Param('id') id: string, @RestId() restId: string) {
return this.ordersService.prepareOrder(id, restId);
} }
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@@ -68,8 +77,8 @@ export class OrdersController {
@Patch('admin/orders/:orderId/reject') @Patch('admin/orders/:orderId/reject')
@ApiOperation({ summary: 'Reject an order' }) @ApiOperation({ summary: 'Reject an order' })
@ApiParam({ name: 'orderId', description: 'Order ID' }) @ApiParam({ name: 'orderId', description: 'Order ID' })
rejectOrder(@Param('orderId') orderId: string) { rejectOrder(@Param('orderId') orderId: string, @RestId() restId: string) {
return this.ordersService.acceptOrder(orderId); return this.ordersService.rejectOrder(orderId, restId);
} }
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@@ -77,7 +86,7 @@ export class OrdersController {
@Patch('admin/orders/:orderId/ready') @Patch('admin/orders/:orderId/ready')
@ApiOperation({ summary: 'Ready for pickup or delivery ' }) @ApiOperation({ summary: 'Ready for pickup or delivery ' })
@ApiParam({ name: 'orderId', description: 'Order ID' }) @ApiParam({ name: 'orderId', description: 'Order ID' })
readyForPickup(@Param('orderId') orderId: string) { readyForPickup(@Param('orderId') orderId: string, @RestId() restId: string) {
return this.ordersService.readyForDelivery(orderId); return this.ordersService.readyForDelivery(orderId, restId);
} }
} }
+20 -10
View File
@@ -252,9 +252,9 @@ export class OrdersService {
}); });
} }
async findOne(id: string): Promise<Order> { async findOne(id: string, restId: string): Promise<Order> {
const order = await this.orderRepository.findOne( const order = await this.orderRepository.findOne(
{ id }, { id, restaurant: { id: restId } },
{ populate: ['user', 'restaurant', 'deliveryMethod', 'address', 'paymentMethod', 'items', 'items.food'] }, { populate: ['user', 'restaurant', 'deliveryMethod', 'address', 'paymentMethod', 'items', 'items.food'] },
); );
if (!order) { if (!order) {
@@ -263,8 +263,8 @@ export class OrdersService {
return order; return order;
} }
async acceptOrder(orderId: string) { async acceptOrder(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId }); const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) { if (!order) {
throw new NotFoundException('Order not found'); throw new NotFoundException('Order not found');
} }
@@ -273,8 +273,18 @@ export class OrdersService {
return order; return order;
} }
async rejectOrder(orderId: string) { async prepareOrder(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId }); const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) {
throw new NotFoundException('Order not found');
}
order.status = OrderStatus.Confirmed;
await this.em.persistAndFlush(order);
return order;
}
async rejectOrder(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) { if (!order) {
throw new NotFoundException('Order not found'); throw new NotFoundException('Order not found');
} }
@@ -283,8 +293,8 @@ export class OrdersService {
return order; return order;
} }
async readyForDelivery(orderId: string) { async readyForDelivery(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId }); const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) { if (!order) {
throw new NotFoundException('Order not found'); throw new NotFoundException('Order not found');
} }
@@ -312,8 +322,8 @@ export class OrdersService {
return order; return order;
} }
async cancelOrder(orderId: string) { async cancelOrder(orderId: string, restId: string) {
const order = await this.em.findOne(Order, { id: orderId }); const order = await this.em.findOne(Order, { id: orderId, restaurant: { id: restId } });
if (!order) { if (!order) {
throw new NotFoundException('Order not found'); throw new NotFoundException('Order not found');
} }