2022-02-09 11:44:08 +05:30
|
|
|
import axios from 'api';
|
|
|
|
|
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
|
|
|
|
|
import { AxiosError } from 'axios';
|
|
|
|
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
2022-05-03 15:27:09 +05:30
|
|
|
import { PayloadProps, Props } from 'types/api/user/getUser';
|
2022-02-09 11:44:08 +05:30
|
|
|
|
2022-05-03 15:27:09 +05:30
|
|
|
const getUser = async (
|
2022-02-09 11:44:08 +05:30
|
|
|
props: Props,
|
|
|
|
|
): Promise<SuccessResponse<PayloadProps> | ErrorResponse> => {
|
|
|
|
|
try {
|
2022-05-03 15:27:09 +05:30
|
|
|
const response = await axios.get(`/user/${props.userId}`, {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `bearer ${props.token}`,
|
|
|
|
|
},
|
2022-02-09 11:44:08 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
statusCode: 200,
|
|
|
|
|
error: null,
|
2022-05-04 12:31:37 +05:30
|
|
|
message: 'Success',
|
2022-02-09 11:44:08 +05:30
|
|
|
payload: response.data,
|
|
|
|
|
};
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return ErrorResponseHandler(error as AxiosError);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-03 15:27:09 +05:30
|
|
|
export default getUser;
|