Skip to content

Commit

Permalink
hotfix(placeMin): convertion Float to Int
Browse files Browse the repository at this point in the history
  • 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.
123 changes: 61 additions & 62 deletions src/shared/api/places.api.ts
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;
}
};

0 comments on commit bcbab31

Please sign in to comment.