fix issue, add transit flow, fix cancellation

This commit is contained in:
Marshal
2026-08-28 22:13:49 +00:00
parent 3015de7508
commit 7e163088d9
50 changed files with 2787 additions and 337 deletions

View File

@@ -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();
}