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 { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import { OrderPrintValueDto } from './order-print-value.dto';
|
import { OrderPrintValueDto } from './order-print-value.dto';
|
||||||
|
|
||||||
export class CreateOrderPrintDto {
|
export class CreateOrderPrintDto {
|
||||||
|
@ApiProperty({ example: 'فرم چاپ سفارش' })
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
title: string;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
type: [OrderPrintValueDto],
|
type: [OrderPrintValueDto],
|
||||||
example: [{ fieldId: '', value: '' }],
|
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 { BaseEntity } from 'src/common/entities/base.entity';
|
||||||
import { Order } from './order.entity';
|
import { Order } from './order.entity';
|
||||||
import { OrderPrintValue } from './order-print-value.entity';
|
import { OrderPrintValue } from './order-print-value.entity';
|
||||||
@@ -7,6 +7,9 @@ import { OrderPrintValue } from './order-print-value.entity';
|
|||||||
export class OrderPrint extends BaseEntity {
|
export class OrderPrint extends BaseEntity {
|
||||||
[OptionalProps]?: 'createdAt' | 'deletedAt';
|
[OptionalProps]?: 'createdAt' | 'deletedAt';
|
||||||
|
|
||||||
|
@Property()
|
||||||
|
title: string;
|
||||||
|
|
||||||
@OneToMany(() => OrderPrintValue, (value) => value.orderPrint, { orphanRemoval: true })
|
@OneToMany(() => OrderPrintValue, (value) => value.orderPrint, { orphanRemoval: true })
|
||||||
values = new Collection<OrderPrintValue>(this);
|
values = new Collection<OrderPrintValue>(this);
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export interface IOrderPrintValue {
|
|||||||
|
|
||||||
export interface IOrderPrintResponse {
|
export interface IOrderPrintResponse {
|
||||||
id: string;
|
id: string;
|
||||||
|
title: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
deletedAt?: Date;
|
deletedAt?: Date;
|
||||||
fileds: IOrderPrintValue[];
|
fileds: IOrderPrintValue[];
|
||||||
|
|||||||
@@ -377,8 +377,9 @@ export class OrderService {
|
|||||||
if (print) {
|
if (print) {
|
||||||
await this.em.populate(print, ['values']);
|
await this.em.populate(print, ['values']);
|
||||||
print.values.removeAll();
|
print.values.removeAll();
|
||||||
|
print.title = dto.title;
|
||||||
} else {
|
} else {
|
||||||
print = this.em.create(OrderPrint, { order });
|
print = this.em.create(OrderPrint, { order, title: dto.title });
|
||||||
}
|
}
|
||||||
|
|
||||||
this.assignPrintValues(print, dto.fields, fieldMap);
|
this.assignPrintValues(print, dto.fields, fieldMap);
|
||||||
@@ -401,6 +402,7 @@ export class OrderService {
|
|||||||
private serializeOrderPrint(print: OrderPrint): IOrderPrintResponse {
|
private serializeOrderPrint(print: OrderPrint): IOrderPrintResponse {
|
||||||
return {
|
return {
|
||||||
id: print.id,
|
id: print.id,
|
||||||
|
title: print.title,
|
||||||
createdAt: print.createdAt,
|
createdAt: print.createdAt,
|
||||||
deletedAt: print.deletedAt,
|
deletedAt: print.deletedAt,
|
||||||
fileds: print.values.getItems().map((item) => ({
|
fileds: print.values.getItems().map((item) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user