75 lines
1.6 KiB
TypeScript
75 lines
1.6 KiB
TypeScript
import { BaseDto } from 'src/core/modules/infrastructure/dto/base.dto';
|
|
import {
|
|
AdditionalFormula,
|
|
SalesPriceFormulaEntity,
|
|
} from '../../domain/entities/sales-price-formula.entity';
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
import { ValidateIf, ValidateNested } from 'class-validator';
|
|
import { Exclude } from 'class-transformer';
|
|
import { Any } from 'typeorm';
|
|
import { FormulaType } from '../../constants';
|
|
|
|
export class AdditionalFormulaDto implements AdditionalFormula {
|
|
@ApiProperty({
|
|
type: Any,
|
|
required: false,
|
|
})
|
|
@ValidateIf((body) => body.formula_render)
|
|
formula_render: any;
|
|
|
|
@ApiProperty({
|
|
type: String,
|
|
required: false,
|
|
})
|
|
@ValidateIf((body) => body.formula_string)
|
|
formula_string: string;
|
|
|
|
@ApiProperty({
|
|
type: String,
|
|
required: false,
|
|
})
|
|
@ValidateIf((body) => body.value_for)
|
|
value_for: string;
|
|
}
|
|
|
|
export class SalesPriceFormulaDto
|
|
extends BaseDto
|
|
implements SalesPriceFormulaEntity
|
|
{
|
|
@ApiProperty({
|
|
type: Any,
|
|
required: false,
|
|
})
|
|
@ValidateIf((body) => body.formula_render)
|
|
formula_render: any;
|
|
|
|
@ApiProperty({
|
|
type: String,
|
|
required: false,
|
|
})
|
|
@ValidateIf((body) => body.formula_string)
|
|
formula_string: string;
|
|
|
|
@Exclude()
|
|
example_formula: string;
|
|
|
|
@Exclude()
|
|
example_result: number;
|
|
|
|
@Exclude()
|
|
value_for: string;
|
|
|
|
@Exclude()
|
|
type: FormulaType;
|
|
|
|
@ApiProperty({
|
|
type: [AdditionalFormulaDto],
|
|
default: AdditionalFormulaDto,
|
|
})
|
|
@ValidateIf(({ additional }) => {
|
|
return additional != null;
|
|
})
|
|
@ValidateNested({ each: true })
|
|
additional: AdditionalFormulaDto[];
|
|
}
|