diff --git a/src/userRoute.ts b/src/userRoute.ts index 52d18b4..6c526bb 100644 --- a/src/userRoute.ts +++ b/src/userRoute.ts @@ -106,7 +106,11 @@ async function getAllUser( return and(...conditions); }, }); - return users; + + return users.map((u) => ({ + ...u, + phone: hidePhone(u.phone), + })); } async function createUser( newUser: UserInsertSchema, @@ -210,3 +214,8 @@ function isValidThaiID(id: string) { const checkSum = (11 - (sum % 11)) % 10; return checkSum === Number(id[12]); } + +function hidePhone(phone: string | null) { + if (phone === null) return phone; + return phone.slice(0, 2).concat("******").concat(phone.slice(-3)); +}