Refatorando código e correções

This commit is contained in:
Matheus Albino Brunhara
2022-05-28 11:47:58 -05:00
parent e79cb353b2
commit 2c3ee6aeae
5 changed files with 110 additions and 70 deletions

View File

@@ -0,0 +1,53 @@
import * as usersRoutes from "../api/users";
interface getByIdReturn {
userData?: {
name: string;
lastname: string;
email: string;
birth_date: string;
bio: string;
},
error?: {
errorMessage: string;
}
}
interface getByIdRes {
status: string;
message: string;
userId?: string;
data: {
name: string;
lastname: string;
email: string;
birth_date: string;
bio: string;
},
}
const getById = async (userId: string): Promise<getByIdReturn> => {
try {
let res: getByIdRes = await usersRoutes.getById(userId)
if (res.status === "error") {
return {
error: {
errorMessage: res.message,
}
};
}
return {
userData: res.data,
};
} catch(err) {
return {
error: {
errorMessage: "Por favor, autentique-se.",
}
};
}
};
export default { getById }