structure
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
import { Controller, Get, Post, Param, UseGuards, Patch, Query } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
|
||||
import { OrdersService } from '../providers/orders.service';
|
||||
import { AuthGuard } from '../../auth/guards/auth.guard';
|
||||
import { UserId } from '../../../common/decorators/user-id.decorator';
|
||||
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
||||
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
||||
import { FindOrdersDto } from '../dto/find-orders.dto';
|
||||
|
||||
@ApiTags('orders')
|
||||
@Controller()
|
||||
export class OrdersController {
|
||||
constructor(private readonly ordersService: OrdersService) {}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Post('public/checkout')
|
||||
@ApiOperation({ summary: 'Checkout : create order and payment record' })
|
||||
checkout(@UserId() userId: string, @RestId() restaurantId: string) {
|
||||
return this.ordersService.checkout(userId, restaurantId);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('public/orders')
|
||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||
findAll(@RestId() restId: string, @Query() dto: FindOrdersDto, @UserId() userId: string) {
|
||||
return this.ordersService.findAllForUser(restId, dto, userId);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get an order By id for User' })
|
||||
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||
@Get('public/orders/:orderId')
|
||||
findOne(@Param('orderId') orderId: string, @RestId() restId: string) {
|
||||
return this.ordersService.findOne(orderId, restId);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Patch('public/orders/:id/cancel')
|
||||
@ApiOperation({ summary: 'Cancel an order By User' })
|
||||
@ApiParam({ name: 'id', description: 'Order ID' })
|
||||
cancelOrder(@Param('id') id: string, @RestId() restId: string) {
|
||||
return this.ordersService.cancelOrderAsUser(id, restId);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('admin/orders')
|
||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||
findAllAdmin(@RestId() restId: string, @Query() dto: FindOrdersDto) {
|
||||
return this.ordersService.findAllForAdmin(restId, dto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get an order By id for User' })
|
||||
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||
@Get('admin/orders/:orderId')
|
||||
findOneAsAdmin(@Param('orderId') orderId: string, @RestId() restId: string) {
|
||||
return this.ordersService.findOne(orderId, restId);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Patch('admin/orders/:orderId/confirm')
|
||||
@ApiOperation({ summary: 'Accept an order' })
|
||||
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||
acceptOrder(@Param('orderId') orderId: string, @RestId() restId: string) {
|
||||
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)
|
||||
@ApiBearerAuth()
|
||||
@Patch('admin/orders/:orderId/reject')
|
||||
@ApiOperation({ summary: 'Reject an order' })
|
||||
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||
rejectOrder(@Param('orderId') orderId: string, @RestId() restId: string) {
|
||||
return this.ordersService.rejectOrder(orderId, restId);
|
||||
}
|
||||
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
// @ApiBearerAuth()
|
||||
// @Patch('admin/orders/:orderId/ready')
|
||||
// @ApiOperation({ summary: 'Ready for pickup or delivery ' })
|
||||
// @ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||
// readyForPickup(@Param('orderId') orderId: string, @RestId() restId: string) {
|
||||
// return this.ordersService.readyForDelivery(orderId, restId);
|
||||
// }
|
||||
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
// @ApiBearerAuth()
|
||||
// @Patch('admin/orders/:orderId/delivered')
|
||||
// @ApiOperation({ summary: 'Mark an order as delivered' })
|
||||
// @ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||
// markAsDelivered(@Param('orderId') orderId: string, @RestId() restId: string) {
|
||||
// return this.ordersService.markAsDelivered(orderId, restId);
|
||||
// }
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Patch('admin/orders/:orderId/:status')
|
||||
@ApiOperation({ summary: 'Update an order status' })
|
||||
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||
@ApiParam({
|
||||
name: 'status',
|
||||
description: 'Order status',
|
||||
enum: [
|
||||
'readyForCustomerPickup',
|
||||
'readyForDineIn',
|
||||
'readyForDeliveryCar',
|
||||
'readyForDeliveryCourier',
|
||||
'shipping',
|
||||
'delivered',
|
||||
],
|
||||
})
|
||||
updateStatus(@Param('orderId') orderId: string, @Param('status') status: string, @RestId() restId: string) {
|
||||
return this.ordersService.updateStatus(orderId, status, restId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user