Added complete validation for expert claim submit state

This commit is contained in:
SepehrYahyaee
2026-09-05 17:33:23 +03:30
parent feacad58ca
commit e48dffef89
6 changed files with 166 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ import {
ArrayMinSize,
IsBoolean,
IsOptional,
ValidateIf,
ValidateNested,
IsEnum,
IsInt,
@@ -15,6 +16,7 @@ import { IsRepairLineAmountToman } from 'src/common/validators/repair-line-amoun
import { ClaimRequiredDocumentType } from 'src/Types&Enums/claim-request-management/required-document-type.enum';
import { DamagedPartItem } from 'src/claim-request-management/dto/capture-requirements-v2.dto';
import { DaghiOption } from 'src/Types&Enums/claim-request-management/daghi-option.enum';
import { TypeOfDamage } from 'src/Types&Enums/claim-request-management/type-of-damage.enum';
export class DaghiDetailsV2Dto {
@ApiProperty({
enum: DaghiOption,
@@ -27,8 +29,12 @@ export class DaghiDetailsV2Dto {
@ApiPropertyOptional({
description: `Required when option is '${DaghiOption.RECYCLED_PARTS_VALUE}' (Toman)`,
})
@IsOptional()
@ValidateIf(
(daghi: DaghiDetailsV2Dto) =>
daghi.option === DaghiOption.RECYCLED_PARTS_VALUE,
)
@IsString()
@IsNotEmpty()
@IsRepairLineAmountToman()
price?: string;
@@ -48,14 +54,23 @@ export class PartPricingV2Dto {
@IsInt()
partId: number;
@ApiProperty({ example: 'Minor' })
@IsString()
typeOfDamage: string;
@ApiProperty({
example: "5000000",
description: "Part price in Toman (integer string). Use 0 if the full amount is in salary.",
enum: TypeOfDamage,
description: "'repair' requires price; 'change' may omit it.",
})
@IsEnum(TypeOfDamage)
typeOfDamage: TypeOfDamage;
@ApiPropertyOptional({
example: "5000000",
description: "Required for repair lines; omitted for change lines. Use 0 if the full amount is in salary.",
})
@ValidateIf(
(part: PartPricingV2Dto) =>
part.typeOfDamage === TypeOfDamage.Repair ||
(part.price != null &&
(typeof part.price !== 'string' || part.price.trim() !== '')),
)
@IsString()
@IsNotEmpty()
@IsRepairLineAmountToman({ allowZero: true })
@@ -76,10 +91,11 @@ export class PartPricingV2Dto {
})
@IsString()
@IsNotEmpty()
@IsRepairLineAmountToman()
@IsRepairLineAmountToman({ allowZero: true })
totalPayment: string;
@ApiProperty({ type: DaghiDetailsV2Dto })
@IsNotEmpty()
@ValidateNested()
@Type(() => DaghiDetailsV2Dto)
daghi: DaghiDetailsV2Dto;