Files
tcc-vamos-frontend/src/services/functions/usersService.ts
2022-06-20 04:05:34 -05:00

95 lines
1.6 KiB
TypeScript

import * as usersRoutes from "../api/users";
interface getByIdReturn {
userData?: {
name: string;
lastname: string;
email: string;
phone_number: string;
birth_date: string;
bio: string;
document_type: string;
document: string;
},
error?: {
errorMessage: string;
}
}
interface getByIdRes {
status: string;
message: string;
userId?: string;
data: {
name: string;
lastname: string;
email: string;
phone_number: string;
birth_date: string;
bio: string;
document_type: string;
document: 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.",
}
};
}
};
interface getByIdReturn {
data?: {
phone: '',
whatsapp: '',
facebook: '',
telegram: '',
},
error?: {
errorMessage: string;
}
}
const getUserSocialInfo = async (userId: string): Promise<getByIdReturn> => {
try {
let res: getByIdRes = await usersRoutes.getSocialInfo(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, getUserSocialInfo }