2025-12-17 13:16:55 -03:00
|
|
|
import api from './api';
|
|
|
|
|
import { Category } from '../types/Category';
|
|
|
|
|
|
|
|
|
|
export const categoryService = {
|
|
|
|
|
getAll: async (): Promise<Category[]> => {
|
|
|
|
|
const response = await api.get<Category[]>('/categories');
|
|
|
|
|
return response.data;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getById: async (id: number): Promise<Category> => {
|
|
|
|
|
const response = await api.get<Category>(`/categories/${id}`);
|
|
|
|
|
return response.data;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
create: async (category: Partial<Category>): Promise<Category> => {
|
|
|
|
|
const response = await api.post<Category>('/categories', category);
|
|
|
|
|
return response.data;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
update: async (id: number, category: Partial<Category>): Promise<void> => {
|
|
|
|
|
await api.put(`/categories/${id}`, category);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
delete: async (id: number): Promise<void> => {
|
|
|
|
|
await api.delete(`/categories/${id}`);
|
2025-12-17 13:21:50 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getOperations: async (id: number): Promise<import('../types/Operation').Operation[]> => {
|
|
|
|
|
const response = await api.get(`/categories/${id}/operations`);
|
|
|
|
|
return response.data;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
addOperation: async (categoryId: number, operationId: number): Promise<void> => {
|
|
|
|
|
await api.post(`/categories/${categoryId}/operations/${operationId}`);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
removeOperation: async (categoryId: number, operationId: number): Promise<void> => {
|
|
|
|
|
await api.delete(`/categories/${categoryId}/operations/${operationId}`);
|
2025-12-17 13:16:55 -03:00
|
|
|
}
|
|
|
|
|
};
|