hard delete order
This commit is contained in:
@@ -36,7 +36,7 @@ export class AdminController {
|
||||
return admin;
|
||||
}
|
||||
|
||||
@Get('admin/admins/profile')
|
||||
@Get('admin/admins/me')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ADMINS)
|
||||
@ApiOperation({ summary: 'admin' })
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Entity, Index, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
|
||||
@Entity({ tableName: 'otps' })
|
||||
@Entity({ tableName: 'otp' })
|
||||
@Index({ properties: ['phone'] })
|
||||
export class Otp {
|
||||
[OptionalProps]?: 'createdAt'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Controller, Get, Post, Param, UseGuards, Patch, Query, Body } from '@nestjs/common';
|
||||
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';
|
||||
@@ -55,6 +55,13 @@ export class OrderController {
|
||||
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/create-invoice')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiOperation({ summary: 'Create invoice for new order' })
|
||||
@@ -68,6 +75,8 @@ export class OrderController {
|
||||
assignDesigner(@Param('orderId') orderId: string, @Body() body: AssignDesignerDto) {
|
||||
return this.orderService.asignDesigner(orderId, body.designerId);
|
||||
}
|
||||
|
||||
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
// @Permissions(Permission.MANAGE_ORDERS)
|
||||
// @Get('admin/orders')
|
||||
|
||||
@@ -93,7 +93,8 @@ export class OrderService {
|
||||
user,
|
||||
attachments,
|
||||
status: TicketStatus.PENDING,
|
||||
admin: null
|
||||
admin: null,
|
||||
order
|
||||
})
|
||||
em.persist(ticket)
|
||||
|
||||
@@ -173,7 +174,8 @@ export class OrderService {
|
||||
user,
|
||||
attachments,
|
||||
status: TicketStatus.PENDING,
|
||||
admin: null
|
||||
admin: null,
|
||||
order
|
||||
})
|
||||
|
||||
em.persist(ticket)
|
||||
@@ -283,7 +285,7 @@ export class OrderService {
|
||||
}
|
||||
|
||||
order.designer = designer
|
||||
order.status=OrderStatusEnum.IN_DESIGN
|
||||
order.status = OrderStatusEnum.IN_DESIGN
|
||||
|
||||
|
||||
await this.em.persistAndFlush(order)
|
||||
@@ -291,4 +293,26 @@ export class OrderService {
|
||||
return order
|
||||
|
||||
}
|
||||
|
||||
async hardDeleteOrder(orderId: string) {
|
||||
const order = await this.orderRepository.findOne({ id: orderId })
|
||||
if (!order) {
|
||||
throw new BadRequestException("Order not found")
|
||||
}
|
||||
if (![OrderStatusEnum.DRAFT, OrderStatusEnum.INVOICED].includes(order.status)) {
|
||||
throw new BadRequestException("Order status must be of of Drfat or Invoiced")
|
||||
}
|
||||
if (order.payments.length > 0) {
|
||||
throw new BadRequestException("order with payments can not be deleted!")
|
||||
}
|
||||
await this.em.transactional(async (em) => {
|
||||
await this.orderRepository.nativeDelete(order)
|
||||
await this.orderItemRepository.nativeDelete({ order: { id: orderId } })
|
||||
await this.ticketRepository.nativeDelete({ order: { id: orderId } })
|
||||
await em.flush()
|
||||
})
|
||||
|
||||
return { message: "Order deleted successfully" }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { User } from "../../user/entities/user.entity";
|
||||
import { TicketStatus } from "../enums/ticket-status.enum";
|
||||
import { Admin } from 'src/modules/admin/entities/admin.entity';
|
||||
import { Order } from 'src/modules/order/entities/order.entity';
|
||||
|
||||
@Entity()
|
||||
export class Ticket extends BaseEntity {
|
||||
@@ -39,4 +40,7 @@ export class Ticket extends BaseEntity {
|
||||
|
||||
@Property({ type: 'json' })
|
||||
attachments: string[]
|
||||
|
||||
@ManyToOne(() => Order)
|
||||
order!: Order
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user