Create Validator class
- Create Validation Utility methods
import { Logger } from "@nestjs/common";
import { ValidationException } from "./exception/validation-exception";
export class Validator {
private static readonly logger = new Logger(Validator.name);
static isValidString(input: string, message: string) {
if (input == null || input.trim() == "") {
throw new ValidationException(message);
}
}
static isValidNumber(input: number, message: string) {
try {
if (input == null || input < 0 ) {
throw new ValidationException(message);
}
} catch (err) {
throw new ValidationException(message);
}
}
static isValidEmail(input: string, message: string) {
if (input == null || input.trim() == "") {
throw new ValidationException(message);
}
}
}