hide phone number from public

This commit is contained in:
2024-04-19 19:39:26 +07:00
parent 406f433984
commit 7ab206943e

View File

@@ -106,7 +106,11 @@ async function getAllUser(
return and(...conditions); return and(...conditions);
}, },
}); });
return users;
return users.map((u) => ({
...u,
phone: hidePhone(u.phone),
}));
} }
async function createUser( async function createUser(
newUser: UserInsertSchema, newUser: UserInsertSchema,
@@ -210,3 +214,8 @@ function isValidThaiID(id: string) {
const checkSum = (11 - (sum % 11)) % 10; const checkSum = (11 - (sum % 11)) % 10;
return checkSum === Number(id[12]); 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));
}