This commit is contained in:
@@ -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: '' }],
|
||||
|
||||
@@ -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<OrderPrintValue>(this);
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ export interface IOrderPrintValue {
|
||||
|
||||
export interface IOrderPrintResponse {
|
||||
id: string;
|
||||
title: string;
|
||||
createdAt: Date;
|
||||
deletedAt?: Date;
|
||||
fileds: IOrderPrintValue[];
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
Reference in New Issue
Block a user