This commit is contained in:
2026-02-22 11:41:44 +03:30
parent bada696f78
commit 973a4596af
4 changed files with 25 additions and 6 deletions
@@ -99,9 +99,9 @@ export class OrderController {
@Post('admin/orders/:orderId/print')
@UseGuards(AdminAuthGuard)
@Permissions(PermissionEnum.ASSIGN_DESIGNER)
@Permissions(PermissionEnum.MANAGE_PRINT)
@ApiOperation({ summary: 'Create order print' })
createPrint(@Param('orderId') orderId: string, @Body() body: CreateOrderPrintDto) {
// return this.orderService.assignDesigner(orderId, body.designerId);
return this.orderService.createPrint(orderId, body);
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ export class OrderPrint extends BaseEntity {
[OptionalProps]?: 'createdAt' | 'deletedAt'
@Property({ type: 'json', nullable: true })
attributes?: IField[]
fileds?: IField[]
@OneToOne(() => Order, (order) => order.print, { mappedBy: 'print' })
+20 -1
View File
@@ -27,6 +27,8 @@ import { InvoiceItem } from 'src/modules/invoice/entities/invoice-item.entity';
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
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';
@Injectable()
export class OrderService {
@@ -233,9 +235,26 @@ export class OrderService {
return order
}
async createPrint(orderId: string, dto: CreateOrderPrintDto): Promise<OrderPrint> {
const order = await this.findOrderOrFail(orderId);
if (order.print) {
order.print.fileds = dto.fields;
await this.em.flush();
return order.print;
}
const print = this.em.create(OrderPrint, {
order,
fileds: dto.fields,
});
await this.em.persistAndFlush(print);
return print;
}
// -----------Hrlper Methods -----------
async findOrderOrFail(id: string): Promise<Order> {
const order = await this.em.findOne(Order, { id }, { populate: ['user', 'type', 'product', 'creator'] });
const order = await this.em.findOne(Order, { id }, { populate: ['user', 'type', 'product', 'creator', 'print'] });
if (!order) {
throw new NotFoundException(`Order with ID ${id} not found.`);
}