order print

This commit is contained in:
2026-02-22 12:37:13 +03:30
parent 2ea4c17c50
commit 520694e4b1
3 changed files with 28 additions and 0 deletions
@@ -104,4 +104,11 @@ export class OrderController {
createPrint(@Param('orderId') orderId: string, @Body() body: CreateOrderPrintDto) {
return this.orderService.createPrint(orderId, body);
}
@Get('admin/orders/:orderId/print')
@UseGuards(AdminAuthGuard)
@ApiOperation({ summary: 'Get order print' })
getPrint(@Param('orderId') orderId: string) {
return this.orderService.getPrint(orderId);
}
}
@@ -29,6 +29,7 @@ import { UpdateStatusAsDesignerDto } from '../dto/update-status-as-designer.dto'
import { UpdateStatusDto } from '../dto/update-status.dto';
import { CreateOrderPrintDto } from '../dto/create-order-print.dto';
import { OrderPrint } from '../entities/print.entity';
import { OrderPrintRepository } from '../repositories/order-print.repository';
@Injectable()
export class OrderService {
@@ -39,6 +40,7 @@ export class OrderService {
private readonly orderRepository: OrderRepository,
private readonly userService: UserService,
private readonly adminService: AdminService,
private readonly orderPrintRepository: OrderPrintRepository,
private readonly productService: ProductService,
private readonly productRepository: ProductRepository,
private readonly ticketRepository: TicketRepository,
@@ -252,6 +254,14 @@ export class OrderService {
return print;
}
async getPrint(orderId:string){
const orderPrint = await this.orderPrintRepository.findOne({ order: { id: orderId } });
if (!orderPrint) {
throw new NotFoundException(`Print with ID ${orderId} not found.`);
}
return orderPrint;
}
// -----------Hrlper Methods -----------
async findOrderOrFail(id: string): Promise<Order> {
const order = await this.em.findOne(Order, { id }, { populate: ['user', 'type', 'product', 'creator', 'print'] });
@@ -0,0 +1,11 @@
import { Injectable } from '@nestjs/common';
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
import { OrderPrint } from '../entities/print.entity';
@Injectable()
export class OrderPrintRepository extends EntityRepository<OrderPrint> {
constructor(readonly em: EntityManager) {
super(em, OrderPrint);
}
}