lib/shared/pipes/not-empty.pipe.ts
Pipe to ensure a value is not empty.
Methods |
constructor(fieldName: string)
|
||||||
Defined in lib/shared/pipes/not-empty.pipe.ts:23
|
||||||
Parameters :
|
transform | ||||||
transform(value: any)
|
||||||
Defined in lib/shared/pipes/not-empty.pipe.ts:26
|
||||||
Parameters :
Returns :
any
|
import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common";
/**
* Pipe to ensure a value is not empty.
*/
@Injectable()
export class NotEmptyPipe implements PipeTransform {
constructor(private readonly fieldName: string) {}
transform(value: any) {
if (!value || Object.keys(value).length === 0) {
throw new BadRequestException(`${this.fieldName} cannot be empty`);
}
return value;
}
}