All files / libs/kernel/api/src/lib/pipes enum.pipe.ts

100% Statements 25/25
100% Branches 3/3
100% Functions 3/3
100% Lines 25/25

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 261x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 10x 10x 1x 1x 10x 10x 1x  
import { Injectable } from '@nestjs/common';
 
import { BaseValidationPipe, type BaseOptions } from './base-validation.pipe';
 
interface EnumOptions extends BaseOptions {
  enum: Record<string, string>;
}
 
@Injectable()
export class EnumPipe extends BaseValidationPipe<unknown> {
  private readonly enumTerms: string[];
 
  public constructor(options: EnumOptions) {
    super(options);
    this.enumTerms = Object.values(options.enum);
  }
 
  public override validateOne(value: unknown): boolean {
    return this.enumTerms.includes(value as string);
  }
 
  public override transformOne(value: unknown): unknown {
    return value;
  }
}