👔 change not found user logic

return false instead of returning the “not found” error if the verbosity parameter is “exists”.
This commit is contained in:
Rafi Arrafif
2025-08-12 18:29:57 +07:00
parent 5d79ffd055
commit a8a57ecce3

View File

@ -20,10 +20,6 @@ export const findUserService = async (payload: getUserDataService) => {
const repoFn = repositoryMap[payload.queryTarget];
if (!repoFn) throw new AppError(503, "Repository handler not found");
// Retrieving user data using the associated repository, if user not found return 404 response
const userData = await repoFn(payload.identifier, payload.options.include);
if (!userData) throw new AppError(404, "User not found");
// Define verbosity levels
const existsVerbosity = ["exists"].includes(payload.options.verbosity);
const fullVerbosity = ["full"].includes(payload.options.verbosity);
@ -31,6 +27,11 @@ export const findUserService = async (payload: getUserDataService) => {
payload.options.verbosity
);
// Retrieving user data using the associated repository, if user not found return 404 response
const userData = await repoFn(payload.identifier, payload.options.include);
if (!userData && existsVerbosity) return false;
if (!userData) throw new AppError(404, "User not found");
// If verbosity in 'exists' level and user is valid then just return 'true' value
if (existsVerbosity) return true;