Files
yara724api/src/workflow-step-management/dto/create-workflow-step.dto.ts
2026-03-14 13:36:05 +03:30

272 lines
6.5 KiB
TypeScript

import { IsNotEmpty, IsString, IsNumber, IsBoolean, IsOptional, IsArray, IsEnum, ValidateNested, IsObject } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { WorkflowStep } from 'src/Types&Enums/blame-request-management/blameWorkflow-steps.enum';
import { ClaimWorkflowStep } from 'src/Types&Enums/claim-request-management/claim-workflow-steps.enum';
import { Types } from 'mongoose';
// Combined enum for validation
const AllWorkflowSteps = { ...WorkflowStep, ...ClaimWorkflowStep };
export class StepFieldDto {
@ApiProperty({
description: 'Unique identifier for the field',
example: '507f1f77bcf86cd799439011'
})
@IsNotEmpty()
id: Types.ObjectId;
@ApiProperty({
description: 'Field name in Farsi',
example: 'فایل ویدیو'
})
@IsNotEmpty()
@IsString()
name_fa: string;
@ApiProperty({
description: 'Field name in English',
example: 'videoFile'
})
@IsNotEmpty()
@IsString()
name_en: string;
@ApiPropertyOptional({
description: 'Field label in Farsi',
example: 'فایل ویدیو'
})
@IsOptional()
@IsString()
label_fa?: string;
@ApiPropertyOptional({
description: 'Field label in English',
example: 'Video File'
})
@IsOptional()
@IsString()
label_en?: string;
@ApiPropertyOptional({
description: 'Placeholder text in Farsi',
example: 'فایل ویدیو خود را آپلود کنید'
})
@IsOptional()
@IsString()
placeholder_fa?: string;
@ApiPropertyOptional({
description: 'Placeholder text in English',
example: 'Upload your video file'
})
@IsOptional()
@IsString()
placeholder_en?: string;
@ApiPropertyOptional({
description: 'Possible values for select/multiselect fields (null for non-select fields)',
example: null,
nullable: true,
default: null
})
@IsOptional()
value?: Object[] | null;
@ApiProperty({
description: 'Data type of the field',
example: 'file',
enum: ['string', 'number', 'boolean', 'date', 'select', 'multiselect', 'file', 'textarea', 'email', 'phone']
})
@IsNotEmpty()
@IsString()
dataType: string;
@ApiPropertyOptional({
description: 'Whether the field is required',
example: true,
default: false
})
@IsOptional()
@IsBoolean()
required?: boolean;
@ApiPropertyOptional({
description: 'Validation rules for the field',
example: { maxSize: 52428800, allowedTypes: ['video/mp4', 'video/webm'] }
})
@IsOptional()
@IsObject()
validation?: Object;
@ApiPropertyOptional({
description: 'Display order of the field in the form',
example: 1
})
@IsOptional()
@IsNumber()
order?: number;
@ApiPropertyOptional({
description: 'Whether the field is active',
example: true,
default: true
})
@IsOptional()
@IsBoolean()
isActive?: boolean;
}
export class CreateWorkflowStepDto {
@ApiProperty({
description: 'Unique key identifying the workflow step (blame or claim)',
example: 'FIRST_VIDEO',
enum: AllWorkflowSteps
})
@IsNotEmpty()
@IsEnum(AllWorkflowSteps)
stepKey: WorkflowStep | ClaimWorkflowStep;
@ApiProperty({
description: 'Workflow type: THIRD_PARTY (blame), CAR_BODY (blame), or CLAIM (claim workflow)',
example: 'THIRD_PARTY',
enum: ['THIRD_PARTY', 'CAR_BODY', 'CLAIM']
})
@IsNotEmpty()
@IsString()
type: string;
@ApiProperty({
description: 'Order number of the step within this workflow type',
example: 2
})
@IsNotEmpty()
@IsNumber()
stepNumber: number;
@ApiPropertyOptional({
description: 'Whether the step is active',
example: true,
default: true
})
@IsOptional()
@IsBoolean()
isActive?: boolean;
@ApiProperty({
description: 'Step name in Farsi',
example: 'ویدیو طرف اول'
})
@IsNotEmpty()
@IsString()
stepName_fa: string;
@ApiProperty({
description: 'Step name in English',
example: 'First Party Video'
})
@IsNotEmpty()
@IsString()
stepName_en: string;
@ApiPropertyOptional({
description: 'Step description in Farsi',
example: 'ضبط ویدیو توسط طرف اول'
})
@IsOptional()
@IsString()
description_fa?: string;
@ApiPropertyOptional({
description: 'Step description in English',
example: 'Video capture by first party'
})
@IsOptional()
@IsString()
description_en?: string;
@ApiPropertyOptional({
description: 'Category of the step within workflow (e.g., INITIAL, FIRST_PARTY, EXPERT)',
example: 'FIRST_PARTY',
enum: ['INITIAL', 'FIRST_PARTY', 'SECOND_PARTY', 'CLAIM', 'EXPERT', 'INSURER', 'FINAL']
})
@IsOptional()
@IsString()
category?: string;
@ApiPropertyOptional({
description: 'Dynamic fields for this step',
type: [StepFieldDto],
example: [
{
id: '507f1f77bcf86cd799439011',
name_fa: 'فایل ویدیو',
name_en: 'videoFile',
label_fa: 'فایل ویدیو',
label_en: 'Video File',
value: null,
dataType: 'file',
required: true,
order: 1,
isActive: true,
validation: {
maxSize: 52428800,
allowedTypes: ['video/mp4', 'video/webm']
}
}
]
})
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => StepFieldDto)
fields?: StepFieldDto[];
@ApiPropertyOptional({
description: 'Steps that must be completed before this step',
example: ['CREATED'],
enum: AllWorkflowSteps,
isArray: true
})
@IsOptional()
@IsArray()
@IsEnum(AllWorkflowSteps, { each: true })
requiredPreviousSteps?: (WorkflowStep | ClaimWorkflowStep)[];
@ApiPropertyOptional({
description: 'Possible next steps after completing this step',
example: ['FIRST_INITIAL_FORM'],
enum: AllWorkflowSteps,
isArray: true
})
@IsOptional()
@IsArray()
@IsEnum(AllWorkflowSteps, { each: true })
nextPossibleSteps?: (WorkflowStep | ClaimWorkflowStep)[];
@ApiPropertyOptional({
description: 'Additional metadata for the step',
example: { icon: 'video', color: '#3B82F6' }
})
@IsOptional()
@IsObject()
metadata?: Record<string, any>;
@ApiPropertyOptional({
description: 'Estimated duration in minutes',
example: 5
})
@IsOptional()
@IsNumber()
estimatedDuration?: number;
@ApiPropertyOptional({
description: 'Roles allowed to access this step',
example: ['user', 'expert', 'admin']
})
@IsOptional()
@IsArray()
@IsString({ each: true })
allowedRoles?: string[];
}