feat: kyc process

This commit is contained in:
Abdalhamid Alhamad
2025-08-07 14:23:33 +03:00
parent 275984954e
commit ee7b365527
73 changed files with 388 additions and 7318 deletions
+1
View File
@@ -1,3 +1,4 @@
// placeholder
export * from './is-above-18';
export * from './is-valid-phone-number';
export * from './is-valid-saudi-id';
@@ -0,0 +1,35 @@
import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
export function isValidSaudiId(validationOptions?: ValidationOptions) {
return function (object: any, propertyName: string) {
registerDecorator({
name: 'isValidSaudiId',
target: object.constructor,
propertyName,
options: {
message: `${propertyName} must be a valid Saudi ID`,
...validationOptions,
},
constraints: [],
validator: {
validate(value: any, args: ValidationArguments) {
if (typeof value !== 'string') return false;
if (!/^[12]\d{9}$/.test(value)) return false;
// Luhn algorithm
let sum = 0;
for (let i = 0; i < 10; i++) {
let digit = parseInt(value[i]);
if (i % 2 === 0) {
digit *= 2;
if (digit > 9) digit -= 9;
}
sum += digit;
}
return sum % 10 === 0;
},
},
});
};
}