Refatorando código e correções
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import * as sessionRoutes from "../services/api/session";
|
||||
import * as sessionRoutes from "../api/session";
|
||||
|
||||
interface refreshSessionReturn {
|
||||
userId?: string;
|
||||
@@ -12,7 +12,7 @@ interface refreshSessionResponse {
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
export const refreshSession = async (): Promise<refreshSessionReturn> => {
|
||||
const refreshSession = async (): Promise<refreshSessionReturn> => {
|
||||
try {
|
||||
let res: refreshSessionResponse = await sessionRoutes.refresh()
|
||||
|
||||
@@ -42,3 +42,5 @@ export const refreshSession = async (): Promise<refreshSessionReturn> => {
|
||||
// }
|
||||
// }
|
||||
};
|
||||
|
||||
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 }
|
||||
@@ -1,35 +0,0 @@
|
||||
import * as usersRoutes from "../../services/api/users";
|
||||
|
||||
interface getByIdReturn {
|
||||
userId?: string;
|
||||
error?: boolean;
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
interface getByIdResponse {
|
||||
status?: string;
|
||||
message?: string;
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
export const getById = async (userId: string): Promise<getByIdReturn> => {
|
||||
try {
|
||||
let res: getByIdResponse = await usersRoutes.getById(userId)
|
||||
|
||||
if (res.status === "error") {
|
||||
return {
|
||||
error: true,
|
||||
errorMessage: res.message,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
userId: res.userId,
|
||||
};
|
||||
} catch(err) {
|
||||
return {
|
||||
error: true,
|
||||
errorMessage: "Por favor, autentique-se.",
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user