You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
649 B
22 lines
649 B
import { ArgumentMetadata, BadRequestException, PipeTransform } from "@nestjs/common";
|
|
import { productStatus } from "./entity/csv.entity";
|
|
|
|
export class ProductStatusValidationPipe implements PipeTransform {
|
|
readonly allowedStatus = [productStatus.AVAILABLE, productStatus.OUT_OF_STOCK];
|
|
|
|
transform(value: any, metadata: ArgumentMetadata): any {
|
|
value = value.toUpperCase();
|
|
|
|
if (!this.isStatusValid(value)) {
|
|
throw new BadRequestException(`${value} is an invalid status.`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
private isStatusValid(status : any) {
|
|
const index = this.allowedStatus.indexOf(status);
|
|
|
|
return index !== -1;
|
|
}
|
|
|
|
} |