mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-25 22:07:56 +00:00
feat: kyc process
This commit is contained in:
@@ -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;
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user