generated from shampsdev/react-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hotfix(placeMin): convertion Float to Int
- Loading branch information
timur
authored and
timur
committed
Dec 23, 2024
1 parent
404a886
commit bcbab31
Showing
1 changed file
with
61 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,75 @@ | ||
import axios from 'axios'; | ||
import { Place } from '@/interfaces/place.interface'; | ||
import { useSettingsStore } from '../stores/settings.store'; | ||
import axios from "axios"; | ||
import { Place } from "@/interfaces/place.interface"; | ||
import { useSettingsStore } from "../stores/settings.store"; | ||
|
||
const API_URL = 'https://dishdash.ru'; | ||
const API_URL = "https://dishdash.ru"; | ||
|
||
export const fetchPlaces = async (): Promise<Place[]> => { | ||
const response = await axios.get<Place[]>(`${API_URL}/api/v1/places`); | ||
return response.data; | ||
const response = await axios.get<Place[]>(`${API_URL}/api/v1/places`); | ||
return response.data; | ||
}; | ||
|
||
export const updatePlace = async (place: Place): Promise<Place> => { | ||
const api_key = useSettingsStore.getState().api_key; | ||
|
||
try { | ||
const response = await axios.put<Place>( | ||
`${API_URL}/api/v1/places`, | ||
{ | ||
...place, | ||
// @ts-expect-error shitty conversion to int | ||
priceMin: parseInt(place.priceAvg), | ||
tags: place.tags.flatMap((x) => x.id), | ||
}, | ||
{ | ||
headers: { | ||
'X-API-Token': api_key, | ||
}, | ||
} | ||
); | ||
return response.data; | ||
} catch (err) { | ||
if (axios.isAxiosError(err)) { | ||
console.error(`Error updating place: ${err.message}`, { | ||
status: err.response?.status, | ||
data: err.response?.data, | ||
}); | ||
} else { | ||
console.error('Unexpected error updating place:', err); | ||
} | ||
const api_key = useSettingsStore.getState().api_key; | ||
|
||
throw err; | ||
try { | ||
const response = await axios.put<Place>( | ||
`${API_URL}/api/v1/places`, | ||
{ | ||
...place, | ||
priceMin: Math.trunc(place.priceAvg), | ||
tags: place.tags.flatMap((x) => x.id), | ||
}, | ||
{ | ||
headers: { | ||
"X-API-Token": api_key, | ||
}, | ||
} | ||
); | ||
return response.data; | ||
} catch (err) { | ||
if (axios.isAxiosError(err)) { | ||
console.error(`Error updating place: ${err.message}`, { | ||
status: err.response?.status, | ||
data: err.response?.data, | ||
}); | ||
} else { | ||
console.error("Unexpected error updating place:", err); | ||
} | ||
|
||
throw err; | ||
} | ||
}; | ||
|
||
export const savePlace = async (place: Place): Promise<Place> => { | ||
const api_key = useSettingsStore.getState().api_key; | ||
const api_key = useSettingsStore.getState().api_key; | ||
|
||
try { | ||
const response = await axios.post<Place>( | ||
`${API_URL}/api/v1/places`, | ||
{ | ||
...place, | ||
priceMin: place.priceAvg, | ||
tags: place.tags.flatMap((x) => x.id), | ||
}, | ||
{ | ||
headers: { | ||
'X-API-Token': api_key, | ||
}, | ||
} | ||
); | ||
return response.data; | ||
} catch (err) { | ||
if (axios.isAxiosError(err)) { | ||
console.error(`Error updating place: ${err.message}`, { | ||
status: err.response?.status, | ||
data: err.response?.data, | ||
}); | ||
} else { | ||
console.error('Unexpected error updating place:', err); | ||
} | ||
|
||
throw err; | ||
try { | ||
const response = await axios.post<Place>( | ||
`${API_URL}/api/v1/places`, | ||
{ | ||
...place, | ||
// shitty convertion to Int | ||
priceMin: Math.trunc(place.priceAvg), | ||
tags: place.tags.flatMap((x) => x.id), | ||
}, | ||
{ | ||
headers: { | ||
"X-API-Token": api_key, | ||
}, | ||
} | ||
); | ||
return response.data; | ||
} catch (err) { | ||
if (axios.isAxiosError(err)) { | ||
console.error(`Error updating place: ${err.message}`, { | ||
status: err.response?.status, | ||
data: err.response?.data, | ||
}); | ||
} else { | ||
console.error("Unexpected error updating place:", err); | ||
} | ||
}; | ||
|
||
throw err; | ||
} | ||
}; |