refactor ticket
This commit is contained in:
@@ -13,6 +13,7 @@ import { AssignDesignerDto } from '../dto/assign-designer.dto';
|
||||
import { UpdateOrderItemDtoAsAdmin, UpdateOrderItemDtoAsUser } from '../dto/update-order-item.dto';
|
||||
import { UpdateOrderAsAdminDto } from '../dto/update-order.dto';
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { CreatePrintFormDto } from '../dto/create-print-form.dto';
|
||||
|
||||
@ApiTags('orders')
|
||||
@ApiBearerAuth()
|
||||
@@ -96,7 +97,7 @@ export class OrderController {
|
||||
}
|
||||
|
||||
@Get('admin/orders')
|
||||
@UseGuards(AuthGuard)
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||
findAllAsAdmin(@Query() dto: FindOrdersDto) {
|
||||
return this.orderService.findOrdersAsAdmin(dto);
|
||||
@@ -117,11 +118,11 @@ export class OrderController {
|
||||
return this.orderService.updateOrderAsAdmin(orderId, dto);
|
||||
}
|
||||
|
||||
@Patch('admin/orders/:orderId/print-form')
|
||||
@Patch('admin/orders/:id/item/:itemId/print')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiOperation({ summary: 'Update Order ' })
|
||||
updateOrderForPrint(@Param('orderId') orderId: string, @Body() dto: UpdateOrderAsAdminDto) {
|
||||
return this.orderService.updateOrderAsAdmin(orderId, dto);
|
||||
@ApiOperation({ summary: 'Create Print form for order item' })
|
||||
createPrintForm(@Param('id') id: string, @Param('itemId') itemId: string, @Body() dto: CreatePrintFormDto) {
|
||||
return this.orderService.createPrintForm(id, +itemId, dto);
|
||||
}
|
||||
|
||||
@Delete('admin/orders/:orderId')
|
||||
@@ -172,4 +173,11 @@ export class OrderController {
|
||||
return this.orderService.updateOrderItemAsAdmin(orderId, +itemId, body);
|
||||
}
|
||||
|
||||
@Get('admin/prints')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||
findAllPrints(@Query() dto: FindOrdersDto) {
|
||||
return this.orderService.findOrdersAsAdmin(dto);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ export class CreateOrderItemAsUserDto {
|
||||
}
|
||||
|
||||
export class CreateOrderItemDtoAsAdmin extends CreateOrderItemAsUserDto {
|
||||
@ApiPropertyOptional({ example: [] })
|
||||
@IsArray()
|
||||
printAttributes?: IField[]
|
||||
// @ApiPropertyOptional({ example: [] })
|
||||
// @IsArray()
|
||||
// printAttributes?: IField[]
|
||||
|
||||
@ApiPropertyOptional({ example: [] })
|
||||
@IsArray()
|
||||
printAttachments?: IAttachment[]
|
||||
// @ApiPropertyOptional({ example: [] })
|
||||
// @IsArray()
|
||||
// printAttachments?: IAttachment[]
|
||||
|
||||
@IsInt()
|
||||
@ApiProperty()
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { IsArray, } from 'class-validator';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { IAttachment, IField } from '../interface/order.interface';
|
||||
|
||||
export class CreatePrintFormDto {
|
||||
@ApiPropertyOptional({ example: [] })
|
||||
@IsArray()
|
||||
printAttributes?: IField[]
|
||||
|
||||
@ApiPropertyOptional({ example: [] })
|
||||
@IsArray()
|
||||
printAttachments?: IAttachment[]
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
OptionalProps,
|
||||
Formula
|
||||
} from '@mikro-orm/core';
|
||||
import { IField, OrderStatusEnum } from '../interface/order.interface';
|
||||
import { OrderStatusEnum } from '../interface/order.interface';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
import { OrderItem } from './order-item.entity';
|
||||
import { Payment } from 'src/modules/payment/entities/payment.entity';
|
||||
|
||||
@@ -34,6 +34,6 @@ import { OrderItemRepository } from './repositories/order-item.repository';
|
||||
controllers: [OrderController],
|
||||
providers: [OrderService, OrderRepository, OrderListeners,
|
||||
OrdersCrone, OrderItemRepository],
|
||||
exports: [OrderRepository, OrderService],
|
||||
exports: [OrderRepository, OrderService, OrderItemRepository],
|
||||
})
|
||||
export class OrderModule { }
|
||||
|
||||
@@ -32,6 +32,7 @@ import { Product } from 'src/modules/product/entities/product.entity';
|
||||
import { AdminService } from 'src/modules/admin/providers/admin.service';
|
||||
import { OrderItem } from '../entities/order-item.entity';
|
||||
import { UpdateOrderAsAdminDto } from '../dto/update-order.dto';
|
||||
import { CreatePrintFormDto } from '../dto/create-print-form.dto';
|
||||
|
||||
|
||||
@Injectable()
|
||||
@@ -161,6 +162,19 @@ export class OrderService {
|
||||
return updated
|
||||
}
|
||||
|
||||
async createPrintForm(orderId: string, itemId: number, dto: CreatePrintFormDto) {
|
||||
|
||||
const orderItem = await this.findOrderItemOrFail(orderId, itemId)
|
||||
|
||||
const updated = await this.updateOrderItem(orderItem, dto)
|
||||
|
||||
// await this.calculateOrder(undefined, orderId)
|
||||
|
||||
// await this.em.flush()
|
||||
|
||||
return updated
|
||||
}
|
||||
|
||||
async removeOrderItemAsAdmin(orderId: string, itemId: number) {
|
||||
|
||||
const orderItem = await this.findOrderItemOrFail(orderId, itemId)
|
||||
@@ -206,6 +220,11 @@ export class OrderService {
|
||||
return orders
|
||||
}
|
||||
|
||||
async findPrints(dto: FindOrdersDto) {
|
||||
const orders = await this.orderRepository.findAllPaginated({...dto,statuses:[]})
|
||||
return orders
|
||||
}
|
||||
|
||||
// async calculateOrder(inputOrder?: Order, orderId?: string) {
|
||||
// let order: undefined | Order = inputOrder
|
||||
|
||||
@@ -509,7 +528,7 @@ export class OrderService {
|
||||
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 this.ticketRepository.nativeDelete({ orderItemorder: { id: orderId } })
|
||||
await em.flush()
|
||||
})
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { FilterQuery } from '@mikro-orm/core';
|
||||
import { Order } from '../entities/order.entity';
|
||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||
import { OrderStatusEnum } from '../interface/order.interface';
|
||||
import { PaymentMethodEnum, PaymentStatusEnum } from '../../payment/interface/payment';
|
||||
import { FindOrdersDto } from '../dto/find-orders.dto';
|
||||
|
||||
|
||||
@@ -94,7 +93,7 @@ export class OrderRepository extends EntityRepository<Order> {
|
||||
limit,
|
||||
offset,
|
||||
orderBy: { [orderBy]: order.toLowerCase() as 'asc' | 'desc' },
|
||||
populate: ['items','items.product'],
|
||||
populate: ['items', 'items.product', 'user'],
|
||||
});
|
||||
|
||||
// Collect all (orderId, productId) pairs for efficient review lookup
|
||||
|
||||
Reference in New Issue
Block a user