Commit fccab38d authored by Alex Segers's avatar Alex Segers

[AFP-111] 🗃 Create 'ManagerService' to handle manager API calls (@asegers)

parent c6fae170
import { Manager } from 'Manager'
import { tokenStorage } from 'utils'
import Axios, { AxiosError } from 'axios'
const BASE_PATH = '/api/managers'
export const authenticate = async (token: string): Promise<Manager> => {
try {
const { data } = await Axios.post(
`${BASE_PATH}/auth`,
{}, // Empty body
{ headers: { Authorization: `Bearer ${token}` } }
)
return data;
} catch (error) {
const { response } = error as AxiosError;
// Get Status Code
return response?.data;
}
}
export const getAccount = async (): Promise<Manager> => {
const token = tokenStorage.get();
try {
const { data } = await Axios.get(
`${BASE_PATH}/account`,
{ headers: { Authorization: `Bearer ${token}` } }
)
return data;
} catch (error) {
const { response } = error as AxiosError;
return response?.data;
}
}
export const updateAccount = async (): Promise<Manager> => {
const token = tokenStorage.get();
try {
const { data } = await Axios.patch(
`${BASE_PATH}/account`,
{}, // Empty body
{ headers: { Authorization: `Bearer ${token}` } }
)
return data;
} catch (error) {
const { response } = error as AxiosError;
return response?.data;
}
}
export const deleteAccount = async () => {
const token = tokenStorage.get();
try {
await Axios.delete(
`${BASE_PATH}/account`,
{ headers: { Authorization: `Bearer ${token}` } }
)
} catch (error) {
const { response } = error as AxiosError;
return response?.data;
}
}
export default {
authenticate,
getAccount,
updateAccount,
deleteAccount
}
\ No newline at end of file
export {default as ManagerService} from './ManagerService'
export {default as OrderService} from './OrderService'
export {default as GoogleAuthService } from './GoogleAuthService'
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment