|
| 1 | +import { Item, ItemGeolocation, UUID } from '@graasp/sdk'; |
| 2 | + |
| 3 | +import { PartialQueryConfigForApi } from '../types'; |
| 4 | +import { verifyAuthentication } from './axios'; |
| 5 | +import { |
| 6 | + buildDeleteItemGeolocationRoute, |
| 7 | + buildGetItemGeolocationRoute, |
| 8 | + buildGetItemsInMapRoute, |
| 9 | + buildPutItemGeolocationRoute, |
| 10 | +} from './routes'; |
| 11 | + |
| 12 | +// eslint-disable-next-line import/prefer-default-export |
| 13 | +export const getItemGeolocation = async ( |
| 14 | + { API_HOST, axios }: PartialQueryConfigForApi, |
| 15 | + id: UUID, |
| 16 | +) => |
| 17 | + axios |
| 18 | + .get<ItemGeolocation>(`${API_HOST}/${buildGetItemGeolocationRoute(id)}`) |
| 19 | + .then(({ data }) => data); |
| 20 | + |
| 21 | +export const putItemGeolocation = async ( |
| 22 | + payload: { |
| 23 | + itemId: Item['id']; |
| 24 | + geolocation: Pick<ItemGeolocation, 'lat' | 'lng'>; |
| 25 | + }, |
| 26 | + { API_HOST, axios }: PartialQueryConfigForApi, |
| 27 | +) => |
| 28 | + verifyAuthentication(() => |
| 29 | + axios |
| 30 | + .put<void>( |
| 31 | + `${API_HOST}/${buildPutItemGeolocationRoute(payload.itemId)}`, |
| 32 | + payload, |
| 33 | + ) |
| 34 | + .then(({ data }) => data), |
| 35 | + ); |
| 36 | + |
| 37 | +export const getItemsInMap = async ( |
| 38 | + payload: { |
| 39 | + lat1: ItemGeolocation['lat']; |
| 40 | + lat2: ItemGeolocation['lat']; |
| 41 | + lng1: ItemGeolocation['lng']; |
| 42 | + lng2: ItemGeolocation['lng']; |
| 43 | + }, |
| 44 | + { API_HOST, axios }: PartialQueryConfigForApi, |
| 45 | +) => |
| 46 | + verifyAuthentication(() => |
| 47 | + axios |
| 48 | + .get<ItemGeolocation[]>(`${API_HOST}/${buildGetItemsInMapRoute(payload)}`) |
| 49 | + .then(({ data }) => data), |
| 50 | + ); |
| 51 | + |
| 52 | +export const deleteItemGeolocation = async ( |
| 53 | + payload: { itemId: UUID }, |
| 54 | + { API_HOST, axios }: PartialQueryConfigForApi, |
| 55 | +) => |
| 56 | + verifyAuthentication(() => |
| 57 | + axios |
| 58 | + .delete<void>( |
| 59 | + `${API_HOST}/${buildDeleteItemGeolocationRoute(payload.itemId)}`, |
| 60 | + ) |
| 61 | + .then(({ data }) => data), |
| 62 | + ); |
0 commit comments