From 2aefeb97d9ebe498046d61064ef9b1c2b18528ff Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sat, 18 Jul 2026 00:15:12 +0330 Subject: [PATCH] order print --- src/modules/order/dto/create-order-print.dto.ts | 7 ++++++- src/modules/order/entities/order-print.entity.ts | 5 ++++- src/modules/order/interface/order.interface.ts | 1 + src/modules/order/providers/order.service.ts | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/modules/order/dto/create-order-print.dto.ts b/src/modules/order/dto/create-order-print.dto.ts index fdea558..b13b783 100644 --- a/src/modules/order/dto/create-order-print.dto.ts +++ b/src/modules/order/dto/create-order-print.dto.ts @@ -1,9 +1,14 @@ -import { IsArray, ValidateNested } from 'class-validator'; +import { IsArray, IsNotEmpty, IsString, ValidateNested } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; import { Type } from 'class-transformer'; import { OrderPrintValueDto } from './order-print-value.dto'; export class CreateOrderPrintDto { + @ApiProperty({ example: 'فرم چاپ سفارش' }) + @IsString() + @IsNotEmpty() + title: string; + @ApiProperty({ type: [OrderPrintValueDto], example: [{ fieldId: '', value: '' }], diff --git a/src/modules/order/entities/order-print.entity.ts b/src/modules/order/entities/order-print.entity.ts index 9364374..cafc198 100644 --- a/src/modules/order/entities/order-print.entity.ts +++ b/src/modules/order/entities/order-print.entity.ts @@ -1,4 +1,4 @@ -import { Collection, Entity, OneToMany, OptionalProps, OneToOne } from '@mikro-orm/core'; +import { Collection, Entity, OneToMany, OptionalProps, OneToOne, Property } from '@mikro-orm/core'; import { BaseEntity } from 'src/common/entities/base.entity'; import { Order } from './order.entity'; import { OrderPrintValue } from './order-print-value.entity'; @@ -7,6 +7,9 @@ import { OrderPrintValue } from './order-print-value.entity'; export class OrderPrint extends BaseEntity { [OptionalProps]?: 'createdAt' | 'deletedAt'; + @Property() + title: string; + @OneToMany(() => OrderPrintValue, (value) => value.orderPrint, { orphanRemoval: true }) values = new Collection(this); diff --git a/src/modules/order/interface/order.interface.ts b/src/modules/order/interface/order.interface.ts index 7aa2bcf..5238d83 100644 --- a/src/modules/order/interface/order.interface.ts +++ b/src/modules/order/interface/order.interface.ts @@ -33,6 +33,7 @@ export interface IOrderPrintValue { export interface IOrderPrintResponse { id: string; + title: string; createdAt: Date; deletedAt?: Date; fileds: IOrderPrintValue[]; diff --git a/src/modules/order/providers/order.service.ts b/src/modules/order/providers/order.service.ts index 4194ec0..0b668b6 100644 --- a/src/modules/order/providers/order.service.ts +++ b/src/modules/order/providers/order.service.ts @@ -377,8 +377,9 @@ export class OrderService { if (print) { await this.em.populate(print, ['values']); print.values.removeAll(); + print.title = dto.title; } else { - print = this.em.create(OrderPrint, { order }); + print = this.em.create(OrderPrint, { order, title: dto.title }); } this.assignPrintValues(print, dto.fields, fieldMap); @@ -401,6 +402,7 @@ export class OrderService { private serializeOrderPrint(print: OrderPrint): IOrderPrintResponse { return { id: print.id, + title: print.title, createdAt: print.createdAt, deletedAt: print.deletedAt, fileds: print.values.getItems().map((item) => ({