79 lines
2.0 KiB
TypeScript
79 lines
2.0 KiB
TypeScript
import axios from "@/config/axios";
|
|
import type {
|
|
CreateCategoryType,
|
|
CreateFoodType,
|
|
GetCategoriesResponseType,
|
|
GetFoodDetailsResponseType,
|
|
GetFoodsParams,
|
|
GetFoodsResponseType,
|
|
GetIconsResponseType,
|
|
} from "../types/Types";
|
|
import type { FilterValues } from "@/components/Filters";
|
|
|
|
export const createFood = async (params: CreateFoodType) => {
|
|
const { data } = await axios.post(`/admin/foods`, params);
|
|
return data;
|
|
};
|
|
|
|
export const getFoods = async (
|
|
params?: GetFoodsParams,
|
|
filters?: FilterValues,
|
|
): Promise<GetFoodsResponseType> => {
|
|
const { data } = await axios.get<GetFoodsResponseType>(`/admin/foods`, {
|
|
params: {
|
|
...params,
|
|
...filters,
|
|
},
|
|
});
|
|
return data;
|
|
};
|
|
|
|
export const getFoodDetails = async (
|
|
id: string,
|
|
): Promise<GetFoodDetailsResponseType> => {
|
|
const { data } = await axios.get<GetFoodDetailsResponseType>(
|
|
`/admin/foods/${id}`,
|
|
);
|
|
return data;
|
|
};
|
|
|
|
export const updateFood = async (id: string, params: CreateFoodType) => {
|
|
const { data } = await axios.patch(`/admin/foods/${id}`, params);
|
|
return data;
|
|
};
|
|
|
|
export const getCategories = async (): Promise<GetCategoriesResponseType> => {
|
|
const { data } = await axios.get<GetCategoriesResponseType>(
|
|
`/admin/categories`,
|
|
);
|
|
return data;
|
|
};
|
|
|
|
export const deleteFood = async (id: string) => {
|
|
const { data } = await axios.delete(`/admin/foods/${id}`);
|
|
return data;
|
|
};
|
|
|
|
export const createCategory = async (params: CreateCategoryType) => {
|
|
const { data } = await axios.post(`/admin/categories`, params);
|
|
return data;
|
|
};
|
|
|
|
export const deleteCategory = async (id: string) => {
|
|
const { data } = await axios.delete(`/admin/categories/${id}`);
|
|
return data;
|
|
};
|
|
|
|
export const updateCategory = async (
|
|
id: string,
|
|
params: CreateCategoryType,
|
|
) => {
|
|
const { data } = await axios.patch(`/admin/categories/${id}`, params);
|
|
return data;
|
|
};
|
|
|
|
export const getIcons = async (): Promise<GetIconsResponseType> => {
|
|
const { data } = await axios.get<GetIconsResponseType>(`/admin/groups/icons`);
|
|
return data;
|
|
};
|