Refatorando código e correções
This commit is contained in:
46
src/services/functions/sessionsService.ts
Normal file
46
src/services/functions/sessionsService.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as sessionRoutes from "../api/session";
|
||||
|
||||
interface refreshSessionReturn {
|
||||
userId?: string;
|
||||
error?: boolean;
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
interface refreshSessionResponse {
|
||||
status?: string;
|
||||
message?: string;
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
const refreshSession = async (): Promise<refreshSessionReturn> => {
|
||||
try {
|
||||
let res: refreshSessionResponse = await sessionRoutes.refresh()
|
||||
|
||||
if (res.status === "error") {
|
||||
return {
|
||||
error: true,
|
||||
errorMessage: res.message,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
userId: res.userId,
|
||||
};
|
||||
} catch(err) {
|
||||
return {
|
||||
error: true,
|
||||
errorMessage: "Por favor, autentique-se.",
|
||||
};
|
||||
}
|
||||
// catch (err: any) {
|
||||
// if (err.response) {
|
||||
// // The client was given an error response (5xx, 4xx)
|
||||
// } else if (err.request) {
|
||||
// // The client never received a response, and the request was never left
|
||||
// } else {
|
||||
// // Anything else
|
||||
// }
|
||||
// }
|
||||
};
|
||||
|
||||
export default { refreshSession }
|
||||
53
src/services/functions/usersService.ts
Normal file
53
src/services/functions/usersService.ts
Normal 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 }
|
||||
Reference in New Issue
Block a user