78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
// src/services/categoryService.ts
|
|
import apiClient from '@/services/axiosSetup';
|
|
import {Category, CategoryTag} from "@/models/Category";
|
|
import {useSpaceStore} from "@/stores/spaceStore"; // Импортируете настроенный экземпляр axios
|
|
|
|
export const getCategories = async (type = null) => {
|
|
const spaceStore = await useSpaceStore();
|
|
|
|
const params = {};
|
|
if (type) {
|
|
params.type = type;
|
|
}
|
|
return await apiClient.get(`/spaces/${spaceStore.space?.id}/categories`, {
|
|
params: params
|
|
});
|
|
};
|
|
|
|
export const getCategoryTypes = async () => {
|
|
const spaceStore = useSpaceStore();
|
|
return await apiClient.get(`/spaces/${spaceStore.space?.id}/categories/types`);
|
|
}
|
|
|
|
export const createCategory = async (category: Category) => {
|
|
const spaceStore = useSpaceStore();
|
|
return await apiClient.post(`/spaces/${spaceStore.space?.id}/categories`, category)
|
|
.then(res => res.data)
|
|
.catch(err => {
|
|
throw err
|
|
})
|
|
};
|
|
|
|
export const editCategoryRequest = async (category: any) => {
|
|
const spaceStore = useSpaceStore();
|
|
return await apiClient.put(`/spaces/${spaceStore.space?.id}/categories/${category.id}`, category)
|
|
.then(res => res.data)
|
|
.catch(err => {
|
|
throw err
|
|
})
|
|
};
|
|
|
|
export const deleteCategory = async (id: number) => {
|
|
const spaceStore = useSpaceStore();
|
|
return await apiClient.delete(`/spaces/${spaceStore.space?.id}/categories/${id}`);
|
|
};
|
|
|
|
export const getCategoriesSumsRequest = async (spaceId: string) => {
|
|
const spaceStore = useSpaceStore();
|
|
return await apiClient.get(`/spaces/${spaceStore.space?.id}/analytics/by-month`)
|
|
}
|
|
|
|
export const getTagsRequest = async () => {
|
|
const spaceStore = useSpaceStore();
|
|
return await apiClient.get(`/spaces/${spaceStore.space?.id}/categories/tags`)
|
|
.then(res => res.data)
|
|
.catch(err => {
|
|
throw err
|
|
})
|
|
}
|
|
|
|
export const createTagRequest = async (tag: CategoryTag) => {
|
|
const spaceStore = useSpaceStore();
|
|
return await apiClient.post(`/spaces/${spaceStore.space?.id}/categories/tags`, tag)
|
|
.then(res => res.data)
|
|
.catch(err => {
|
|
throw err
|
|
})
|
|
}
|
|
|
|
export const deleteTagRequest = async (tag: CategoryTag) => {
|
|
const spaceStore = useSpaceStore();
|
|
return await apiClient.delete(`/spaces/${spaceStore.space?.id}/categories/tags/${tag.code}`)
|
|
.then(res => res.data)
|
|
.catch(err => {
|
|
throw err
|
|
})
|
|
|
|
}
|