28 lines
805 B
TypeScript
28 lines
805 B
TypeScript
|
|
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}`);
|
||
|
|
}
|
||
|
|
};
|