From 7ab206943ebaff417004d90a28f7878a67b88f3e Mon Sep 17 00:00:00 2001 From: Thanu Poptiphueng Date: Fri, 19 Apr 2024 19:39:26 +0700 Subject: [PATCH] hide phone number from public --- src/userRoute.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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)); +}