84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import { Controller, Get, Post, Param, UseGuards, Patch, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
|
|
import { OrdersService } from './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) {
|
|
return this.ordersService.findAll(restId, dto);
|
|
}
|
|
|
|
@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) {
|
|
return this.ordersService.findOne(orderId);
|
|
}
|
|
|
|
@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) {
|
|
return this.ordersService.cancelOrder(id);
|
|
}
|
|
|
|
@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.findAll(restId, dto);
|
|
}
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Patch('admin/orders/:orderId/confirm')
|
|
@ApiOperation({ summary: 'Accept an order' })
|
|
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
|
acceptOrder(@Param('orderId') orderId: string) {
|
|
return this.ordersService.acceptOrder(orderId);
|
|
}
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Patch('admin/orders/:orderId/reject')
|
|
@ApiOperation({ summary: 'Reject an order' })
|
|
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
|
rejectOrder(@Param('orderId') orderId: string) {
|
|
return this.ordersService.acceptOrder(orderId);
|
|
}
|
|
|
|
@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) {
|
|
return this.ordersService.readyForDelivery(orderId);
|
|
}
|
|
}
|