All files / src/llm-orchestration/action-handlers/dto request-context.args.dto.ts

100% Statements 14/14
100% Branches 2/2
100% Functions 3/3
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 407x 7x             7x   9x   9x 12x         2x       7x     7x       7x       7x       7x    
import { IsOptional, IsString, Validate } from 'class-validator';
import {
  ValidatorConstraint,
  ValidatorConstraintInterface,
  ValidationArguments,
} from 'class-validator';
 
@ValidatorConstraint({ name: 'atLeastOneRequired', async: false })
export class IsAtLeastOneOf implements ValidatorConstraintInterface {
  validate(value: any, args: ValidationArguments) {
    const object = args.object as any;
    // args.constraints is the array passed to the decorator, which is ['files', 'folders']
    return args.constraints.some(
      (prop: string) => object[prop] !== undefined && object[prop] !== '',
    );
  }
 
  defaultMessage(args: ValidationArguments) {
    return `At least one of the following must be provided and not empty: ${args.constraints.join(', ')}.`;
  }
}
 
export class RequestContextArgsDto {
  @IsOptional()
  @IsString()
  files?: string;
 
  @IsOptional()
  @IsString()
  folders?: string;
 
  @IsOptional()
  @IsString()
  reason?: string;
 
  // Corrected: Pass a flat array of property names.
  @Validate(IsAtLeastOneOf, ['files', 'folders'])
  _validation: undefined;
}