orders
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
export enum DeliveryMethodEnum {
|
export enum DeliveryMethodEnum {
|
||||||
DineIn = 'dineIn',
|
DineIn = 'dineIn',
|
||||||
Pickup = 'pickup',
|
CustomerPickup = 'customerPickup',
|
||||||
DeliveryCar = 'deliveryCar',
|
DeliveryCar = 'deliveryCar',
|
||||||
DeliveryCourier = 'deliveryCourier',
|
DeliveryCourier = 'deliveryCourier',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
export enum OrderStatus {
|
export enum OrderStatus {
|
||||||
Pending = 'pending',
|
Pending = 'pending',
|
||||||
Confirmed = 'confirmed',
|
Confirmed = 'confirmed',
|
||||||
|
RejectedByRestaurant = 'rejectedByRestaurant',
|
||||||
|
CancelledByUser = 'cancelledByUser',
|
||||||
|
|
||||||
|
ReadyForCustomerPickup = 'readyForCustomerPickup',
|
||||||
|
ReadyForDineIn = 'readyForDineIn',
|
||||||
|
ReadyForDeliveryCar = 'readyForDeliveryCar',
|
||||||
|
ReadyForDeliveryCourier = 'readyForDeliveryCourier',
|
||||||
|
|
||||||
Delivered = 'delivered',
|
Delivered = 'delivered',
|
||||||
Cancelled = 'cancelled',
|
CancelledBySystem = 'cancelledBySystem',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Controller, Get, Post, Param, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Post, Param, UseGuards, Patch } from '@nestjs/common';
|
||||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
|
||||||
import { OrdersService } from './orders.service';
|
import { OrdersService } from './orders.service';
|
||||||
import { AuthGuard } from '../auth/guards/auth.guard';
|
import { AuthGuard } from '../auth/guards/auth.guard';
|
||||||
import { UserId } from '../../common/decorators/user-id.decorator';
|
import { UserId } from '../../common/decorators/user-id.decorator';
|
||||||
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
||||||
import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
|
import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
|
||||||
|
|
||||||
@ApiTags('orders')
|
@ApiTags('orders')
|
||||||
@Controller()
|
@Controller()
|
||||||
export class OrdersController {
|
export class OrdersController {
|
||||||
@@ -27,6 +27,13 @@ export class OrdersController {
|
|||||||
return this.ordersService.findAll(restId);
|
return this.ordersService.findAll(restId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@Get('public/orders/:id')
|
||||||
|
findOne(@Param('id') id: string) {
|
||||||
|
return this.ordersService.findOne(+id);
|
||||||
|
}
|
||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Get('admin/orders')
|
@Get('admin/orders')
|
||||||
@@ -35,17 +42,32 @@ export class OrdersController {
|
|||||||
return this.ordersService.findAll(restId);
|
return this.ordersService.findAll(restId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Get('public/orders/:id')
|
@Patch('admin/orders/:orderId/confirm')
|
||||||
findOne(@Param('id') id: string) {
|
@ApiOperation({ summary: 'Accept an order' })
|
||||||
return this.ordersService.findOne(+id);
|
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||||
|
acceptOrder(@Param('orderId') orderId: string) {
|
||||||
|
return this.ordersService.acceptOrder(orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Patch(':id')
|
@UseGuards(AdminAuthGuard)
|
||||||
// update(@Param('id') id: string, @Body() updateOrderDto: UpdateOrderDto) {
|
@ApiBearerAuth()
|
||||||
// return this.ordersService.update(+id, updateOrderDto);
|
@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 an order' })
|
||||||
|
@ApiParam({ name: 'orderId', description: 'Order ID' })
|
||||||
|
readyForPickup(@Param('orderId') orderId: string) {
|
||||||
|
return this.ordersService.readyForDelivery(orderId);
|
||||||
|
}
|
||||||
|
|
||||||
// @Delete(':id')
|
// @Delete(':id')
|
||||||
// remove(@Param('id') id: string) {
|
// remove(@Param('id') id: string) {
|
||||||
|
|||||||
@@ -250,9 +250,53 @@ export class OrdersService {
|
|||||||
return `This action returns a #${id} order`;
|
return `This action returns a #${id} order`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
async acceptOrder(orderId: string) {
|
||||||
update(id: number, _updateOrderDto: unknown) {
|
const order = await this.em.findOne(Order, { id: orderId });
|
||||||
return `This action updates a #${id} order`;
|
if (!order) {
|
||||||
|
throw new NotFoundException('Order not found');
|
||||||
|
}
|
||||||
|
order.status = OrderStatus.Confirmed;
|
||||||
|
await this.em.persistAndFlush(order);
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
async rejectOrder(orderId: string) {
|
||||||
|
const order = await this.em.findOne(Order, { id: orderId });
|
||||||
|
if (!order) {
|
||||||
|
throw new NotFoundException('Order not found');
|
||||||
|
}
|
||||||
|
order.status = OrderStatus.RejectedByRestaurant;
|
||||||
|
await this.em.persistAndFlush(order);
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
async readyForDelivery(orderId: string) {
|
||||||
|
const order = await this.em.findOne(Order, { id: orderId });
|
||||||
|
if (!order) {
|
||||||
|
throw new NotFoundException('Order not found');
|
||||||
|
}
|
||||||
|
let orderStatus: OrderStatus | undefined;
|
||||||
|
|
||||||
|
switch (order.deliveryMethod.method) {
|
||||||
|
case DeliveryMethodEnum.DeliveryCourier:
|
||||||
|
orderStatus = OrderStatus.ReadyForDeliveryCourier;
|
||||||
|
break;
|
||||||
|
case DeliveryMethodEnum.DeliveryCar:
|
||||||
|
orderStatus = OrderStatus.ReadyForDeliveryCar;
|
||||||
|
break;
|
||||||
|
case DeliveryMethodEnum.DineIn:
|
||||||
|
orderStatus = OrderStatus.ReadyForDineIn;
|
||||||
|
break;
|
||||||
|
case DeliveryMethodEnum.CustomerPickup:
|
||||||
|
orderStatus = OrderStatus.ReadyForCustomerPickup;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new BadRequestException('Invalid delivery method');
|
||||||
|
}
|
||||||
|
|
||||||
|
order.status = orderStatus;
|
||||||
|
await this.em.persistAndFlush(order);
|
||||||
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id: number) {
|
remove(id: number) {
|
||||||
@@ -307,7 +351,7 @@ export class OrdersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update order status to Cancelled
|
// Update order status to Cancelled
|
||||||
order.status = OrderStatus.Cancelled;
|
order.status = OrderStatus.CancelledBySystem;
|
||||||
em.persist(order);
|
em.persist(order);
|
||||||
|
|
||||||
await em.flush();
|
await em.flush();
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ export const deliveryMethodsData: DeliveryMethodData[] = [
|
|||||||
order: 1,
|
order: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
method: DeliveryMethodEnum.Pickup,
|
method: DeliveryMethodEnum.CustomerPickup,
|
||||||
title: 'تحویل در رستوران',
|
title: 'برداشت از رستوران',
|
||||||
description: 'تحویل غذا در محل',
|
description: 'برداشت غذا از رستوران',
|
||||||
deliveryFee: 0,
|
deliveryFee: 0,
|
||||||
minOrderPrice: 0,
|
minOrderPrice: 0,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user