Files
peakskills/lib/data-loader.ts
Julien Froidefond 72b653de19 feat: refactor skills API and database schema
- Replaced file-based skill category loading with API calls in the GET and POST methods of the skills route.
- Added new `SkillsService` for handling skill category operations.
- Updated SQL initialization script to create `skill_categories`, `skills`, and `skill_links` tables with appropriate relationships.
- Enhanced `ApiClient` with methods for loading skill categories and creating new skills, improving API interaction.
- Introduced error handling for skill category creation and loading processes.
2025-08-21 09:55:35 +02:00

37 lines
1.1 KiB
TypeScript

import { SkillCategory, Team } from "./types";
export async function loadSkillCategories(): Promise<SkillCategory[]> {
try {
const response = await fetch("/api/skills");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error("Failed to load skill categories:", error);
return [];
}
}
/**
* Load skill categories from local files (fallback or development mode)
* This is a client-side safe alternative that still uses the API
* For server-side file loading, use loadSkillCategoriesFromFiles from skill-file-loader
*/
export async function loadSkillCategoriesFromAPI(): Promise<SkillCategory[]> {
return loadSkillCategories();
}
export async function loadTeams(): Promise<Team[]> {
try {
const response = await fetch("/api/teams");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error("Failed to load teams:", error);
return [];
}
}