Files
aurak/web/services/noteCategoryService.ts
Developer 0a9588abb7 feat: implement QuestionBank CRUD with pagination and template query
- Add pagination support to findAll (page, limit query params)
- Add findByTemplateId method to service
- Add GET /by-template/:templateId endpoint to controller
- Service already includes CRUD for QuestionBank and QuestionBankItem
2026-04-23 17:19:11 +08:00

46 lines
1.7 KiB
TypeScript

import { API_BASE_URL, NoteCategory } from '../types';
export const noteCategoryService = {
async getAll(token: string): Promise<NoteCategory[]> {
const res = await fetch(`${API_BASE_URL}/v1/note-categories`, {
headers: { 'Authorization': `Bearer ${token}` }
});
if (!res.ok) throw new Error('Failed to fetch categories');
return res.json();
},
async create(token: string, name: string, parentId?: string): Promise<NoteCategory> {
const response = await fetch(`${API_BASE_URL}/v1/note-categories`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, parentId })
})
if (!response.ok) throw new Error('Failed to create category')
return response.json()
},
async update(token: string, id: string, name?: string, parentId?: string): Promise<NoteCategory> {
const response = await fetch(`${API_BASE_URL}/v1/note-categories/${id}`, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, parentId })
})
if (!response.ok) throw new Error('Failed to update category')
return response.json()
},
async delete(token: string, id: string): Promise<void> {
const res = await fetch(`${API_BASE_URL}/v1/note-categories/${id}`, {
method: 'DELETE',
headers: { 'Authorization': `Bearer ${token}` }
});
if (!res.ok) throw new Error('Failed to delete category');
}
};