import { IsNotEmpty, IsBoolean, ValidateIf } from 'class-validator'; import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger'; export class AbstractAttachmentDto { @ApiModelProperty() @IsNotEmpty() fileName: string; @ApiModelProperty() @IsNotEmpty() originalFileName: string; @ApiModelProperty() @IsNotEmpty() mediaType: string; @ApiModelProperty() @IsNotEmpty() fileSize: number; @ApiModelPropertyOptional({ default: false }) @IsBoolean() isCommentAttachment: boolean = false; // Validate this field if the attachment is not for a comment @ApiModelProperty({ required: this.isCommentAttachment ? true : false }) @ValidateIf(o => o.isCommentAttachment ? false : true) @IsNotEmpty() parent?: string; constructor( fileName: string, originalFileName: string, mediaType: string, fileSize: number, isCommentAttachment: boolean, parent?: string, ) { this.fileName = fileName; this.originalFileName = originalFileName; this.mediaType = mediaType; this.fileSize = fileSize; this.parent = parent; this.isCommentAttachment = isCommentAttachment; } }