From bcbab3135c4552a074def4f6fdaf9e879d6d09de Mon Sep 17 00:00:00 2001 From: timur Date: Tue, 24 Dec 2024 01:08:24 +0300 Subject: [PATCH] hotfix(placeMin): convertion Float to Int --- src/shared/api/places.api.ts | 123 +++++++++++++++++------------------ 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/src/shared/api/places.api.ts b/src/shared/api/places.api.ts index 5de25d8..e0e299a 100644 --- a/src/shared/api/places.api.ts +++ b/src/shared/api/places.api.ts @@ -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 => { - const response = await axios.get(`${API_URL}/api/v1/places`); - return response.data; + const response = await axios.get(`${API_URL}/api/v1/places`); + return response.data; }; export const updatePlace = async (place: Place): Promise => { - const api_key = useSettingsStore.getState().api_key; - - try { - const response = await axios.put( - `${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( + `${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 => { - const api_key = useSettingsStore.getState().api_key; + const api_key = useSettingsStore.getState().api_key; - try { - const response = await axios.post( - `${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( + `${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; + } +};