mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 13:38:20 +00:00
fix issue, add transit flow, fix cancellation
This commit is contained in:
@@ -4,25 +4,29 @@ import {
|
||||
ValidationOptions,
|
||||
ValidatorConstraint,
|
||||
ValidatorConstraintInterface,
|
||||
} from 'class-validator';
|
||||
import { isValidPhoneNumber, parsePhoneNumberFromString } from 'libphonenumber-js';
|
||||
} from "class-validator";
|
||||
import {
|
||||
isValidPhoneNumber,
|
||||
parsePhoneNumberFromString,
|
||||
} from "libphonenumber-js";
|
||||
|
||||
/**
|
||||
* Country-aware phone validation. The value is expected as a full international
|
||||
* number (E.164, e.g. "+251911223344"), so the country is derived from the
|
||||
* value itself — no separate country field needed.
|
||||
* number (E.164, e.g. "+25377834567" for Djibouti or "+251911223344" for
|
||||
* Ethiopia), so the country is derived from the value itself — no separate
|
||||
* country field needed.
|
||||
*/
|
||||
@ValidatorConstraint({ name: 'IsValidPhone', async: false })
|
||||
@ValidatorConstraint({ name: "IsValidPhone", async: false })
|
||||
export class IsValidPhoneConstraint implements ValidatorConstraintInterface {
|
||||
validate(value: unknown): boolean {
|
||||
// Empty is allowed here; pair with @IsOptional / @IsNotEmpty as needed.
|
||||
if (value === undefined || value === null || value === '') return true;
|
||||
if (typeof value !== 'string') return false;
|
||||
if (value === undefined || value === null || value === "") return true;
|
||||
if (typeof value !== "string") return false;
|
||||
return isValidPhoneNumber(value);
|
||||
}
|
||||
|
||||
defaultMessage(args: ValidationArguments): string {
|
||||
return `${args.property} must be a valid international phone number (E.164, e.g. +251911223344)`;
|
||||
return `${args.property} must be a complete international phone number (E.164, e.g. +25377834567 or +251911223344)`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +57,7 @@ export function IsValidPhone(validationOptions?: ValidationOptions) {
|
||||
export function normalizeE164(
|
||||
value: string | null | undefined,
|
||||
): string | null | undefined {
|
||||
if (value === undefined || value === null || value === '') return value;
|
||||
const parsed = parsePhoneNumberFromString(value, 'ET');
|
||||
if (value === undefined || value === null || value === "") return value;
|
||||
const parsed = parsePhoneNumberFromString(value, "ET");
|
||||
return parsed?.isValid() ? parsed.number : value.trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user