142 lines
5.1 KiB
TypeScript
142 lines
5.1 KiB
TypeScript
import { Controller, Get, Post, Param, UseGuards, Patch, Query, Body, Delete } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiHeader, ApiBody, ApiQuery } from '@nestjs/swagger';
|
|
import { OrderService } from '../providers/order.service';
|
|
import { AuthGuard } from '../../auth/guards/auth.guard';
|
|
import { UserId } from '../../../common/decorators/user-id.decorator';
|
|
import { FindOrdersDto } from '../dto/find-orders.dto';
|
|
import { Permissions } from 'src/common/decorators/permissions.decorator';
|
|
import { Permission } from 'src/common/enums/permission.enum';
|
|
import { CreateOrderDto } from '../dto/create-order.dto';
|
|
import { CreateInvoiceDto } from '../dto/create-invoice.dto';
|
|
import { AdminId } from 'src/common/decorators/admin-id.decorator';
|
|
import { CreateOrderAsAdminDto } from '../dto/create-order-as-admin.dto';
|
|
import { AssignDesignerDto } from '../dto/assign-designer.dto';
|
|
import { AddOrderItemDto } from '../dto/add-order-item.dto';
|
|
|
|
@ApiTags('orders')
|
|
@ApiBearerAuth()
|
|
@Controller()
|
|
export class OrderController {
|
|
constructor(private readonly orderService: OrderService) { }
|
|
|
|
@Post('public/order')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'create order as user' })
|
|
createOrder(@UserId() userId: string, @Body() body: CreateOrderDto) {
|
|
return this.orderService.createOrder(userId, body);
|
|
}
|
|
|
|
@Get('public/orders')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
|
async findAll(@Query() dto: FindOrdersDto, @UserId() userId: string) {
|
|
const orders = await this.orderService.findAllForUser(userId, dto);
|
|
return orders
|
|
}
|
|
|
|
@Post('public/orders/:orderId/items/:orderItemId')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'Confirm Invoice Item By User' })
|
|
confirmOrderItem(
|
|
@Param('orderId') orderId: string,
|
|
@Param('orderItemId') orderItemId: string,
|
|
@UserId() userId: string
|
|
) {
|
|
return this.orderService.confirmOrderItem(userId, orderId, +orderItemId);
|
|
}
|
|
|
|
|
|
|
|
/*========================== Admin Routes =====================*/
|
|
|
|
@Post('admin/order')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'create order as admin' })
|
|
createOrderAsAdmin(@AdminId() adminId: string, @Body() body: CreateOrderAsAdminDto) {
|
|
return this.orderService.createOrdeAsAdmin(adminId, body);
|
|
}
|
|
|
|
@Delete('admin/orders/:orderId')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'Hard Delete Order ' })
|
|
hardDelete(@Param('orderId') orderId: string) {
|
|
return this.orderService.hardDeleteOrder(orderId);
|
|
}
|
|
|
|
@Post('admin/orders/:orderId/add-item')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'add item to Order ' })
|
|
addItem(@Param('orderId') orderId: string, @Body() body: AddOrderItemDto) {
|
|
return this.orderService.addOrderItem(orderId, body);
|
|
}
|
|
|
|
@Post('admin/orders/:orderId/create-invoice')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'Create invoice for new order' })
|
|
createInvoice(@Param('orderId') orderId: string, @Body() body: CreateInvoiceDto) {
|
|
return this.orderService.createInvoice(orderId, body);
|
|
}
|
|
|
|
@Post('admin/orders/:orderId/assign-designer')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'Assign Order Designer ' })
|
|
assignDesigner(@Param('orderId') orderId: string, @Body() body: AssignDesignerDto) {
|
|
return this.orderService.asignDesigner(orderId, body.designerId);
|
|
}
|
|
|
|
|
|
// @UseGuards(AdminAuthGuard)
|
|
// @Permissions(Permission.MANAGE_ORDERS)
|
|
// @Get('admin/orders')
|
|
// @ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
|
// findAllAdmin(, @Query() dto: FindOrdersDto) {
|
|
// return this.ordersService.findAllForAdmin(, dto);
|
|
// }
|
|
|
|
// @UseGuards(AdminAuthGuard)
|
|
// @Permissions(Permission.MANAGE_ORDERS)
|
|
// @ApiOperation({ summary: 'Get an order By id for User' })
|
|
// @ApiParam({ name: 'orderId', description: 'Order ID' })
|
|
// @Get('admin/orders/:orderId')
|
|
// findOneAsAdmin(@Param('orderId') orderId: string,) {
|
|
// return this.ordersService.findOne(orderId,);
|
|
// }
|
|
|
|
// @UseGuards(AdminAuthGuard)
|
|
// @Permissions(Permission.MANAGE_ORDERS)
|
|
// @Patch('admin/orders/:orderId/:status')
|
|
// @ApiOperation({ summary: 'Update an order status' })
|
|
// @ApiParam({ name: 'orderId', description: 'Order ID' })
|
|
// @ApiBody({ type: UpdateOrderStatusDto })
|
|
// @ApiParam({
|
|
// name: 'status',
|
|
// description: 'Order status',
|
|
// enum: OrderStatus,
|
|
// })
|
|
// updateStatus(
|
|
// @Param('orderId') orderId: string,
|
|
// @Body() dto: UpdateOrderStatusDto,
|
|
// @Param('status') status: OrderStatus,
|
|
// ,
|
|
// ) {
|
|
// return this.ordersService.changeOrderStatus(orderId, , status, 'admin', dto?.desc);
|
|
// }
|
|
|
|
// @UseGuards(AdminAuthGuard)
|
|
// @Permissions(Permission.VIEW_REPORTS)
|
|
// @ApiOperation({ summary: 'Get Stats for report page' })
|
|
// @Get('admin/orders/stats')
|
|
// findStats() {
|
|
// return this.ordersService.getStats();
|
|
// }
|
|
|
|
// @UseGuards(AdminAuthGuard)
|
|
// @Permissions(Permission.VIEW_REPORTS)
|
|
// @ApiOperation({ summary: 'Get product sales pie chart data for last month' })
|
|
|
|
// @Get('admin/orders/product-sales-pie-chart')
|
|
// getproductSalesPieChart() {
|
|
// return this.ordersService.getproductSalesPieChart();
|
|
// }
|
|
}
|