125 lines
4.7 KiB
TypeScript
125 lines
4.7 KiB
TypeScript
import { Controller, Get, Post, Param, UseGuards, Patch, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiHeader } 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';
|
|
import { OrderStatus } from '../interface/order-status';
|
|
|
|
@ApiTags('orders')
|
|
@ApiBearerAuth()
|
|
@ApiHeader({
|
|
name: 'X-Slug',
|
|
required: true,
|
|
schema: {
|
|
type: 'string',
|
|
default: 'zhivan',
|
|
},
|
|
})
|
|
@Controller()
|
|
export class OrdersController {
|
|
constructor(private readonly ordersService: OrdersService) { }
|
|
|
|
@UseGuards(AuthGuard)
|
|
@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)
|
|
@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)
|
|
@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)
|
|
@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)
|
|
@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)
|
|
@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)
|
|
@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.confirmOrder(orderId, restId);
|
|
}
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@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)
|
|
@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)
|
|
@Patch('admin/orders/:orderId/:status')
|
|
@ApiOperation({ summary: 'Update an order status' })
|
|
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
|
@ApiParam({
|
|
name: 'status',
|
|
description: 'Order status',
|
|
enum: OrderStatus,
|
|
})
|
|
updateStatus(@Param('orderId') orderId: string, @Param('status') status: OrderStatus, @RestId() restId: string) {
|
|
return this.ordersService.updateStatus(orderId, status, restId);
|
|
}
|
|
}
|