52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import { API } from './apiSlice'
|
|
|
|
const authHeader = () => {
|
|
const token = localStorage.getItem('token')
|
|
return token ? { Authorization: `Bearer ${token}` } : {}
|
|
}
|
|
|
|
export const locationApi = API.injectEndpoints({
|
|
endpoints: (build) => ({
|
|
createLocation: build.mutation({
|
|
query: ({ specialistId, data }) => ({
|
|
url: `/specialist/${specialistId}/location/create`,
|
|
method: 'POST',
|
|
headers: authHeader(),
|
|
body: JSON.stringify(data),
|
|
}),
|
|
invalidatesTags: ['Specialist'],
|
|
}),
|
|
updateLocation: build.mutation({
|
|
query: ({ specialistId, locationId, data }) => {
|
|
return ({
|
|
url: `/specialist/${specialistId}/location/${locationId}`,
|
|
method: 'PUT',
|
|
headers: authHeader(),
|
|
body: JSON.stringify(data),
|
|
})},
|
|
}),
|
|
deleteLocation: build.mutation({
|
|
query: (locationId) => ({
|
|
url: `/location/${locationId}`,
|
|
method: 'DELETE',
|
|
headers: authHeader(),
|
|
}),
|
|
}),
|
|
getEmptyLocations: build.query({
|
|
query: () => {
|
|
return {
|
|
url: `/locations/empty`,
|
|
headers: authHeader(),
|
|
};
|
|
},
|
|
}),
|
|
}),
|
|
})
|
|
|
|
export const {
|
|
useCreateLocationMutation,
|
|
useUpdateLocationMutation,
|
|
useDeleteLocationMutation,
|
|
useGetEmptyLocationsQuery,
|
|
} = locationApi
|