export interface Skill { id: string; name: string; description: string; icon: string; categoryId: string; category: string; usageCount: number; } export interface Team { id: string; name: string; direction: string; memberCount: number; } export interface TeamMember { id: string; firstName: string; lastName: string; fullName: string; joinedAt: string; } export class AdminManagementService { private static baseUrl = "/api/admin"; // Skills Management static async getSkills(): Promise { const response = await fetch(`${this.baseUrl}/skills`); if (!response.ok) { throw new Error("Failed to fetch skills"); } return response.json(); } static async createSkill( skillData: Omit ): Promise { const response = await fetch(`${this.baseUrl}/skills`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(skillData), }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || "Failed to create skill"); } return response.json(); } static async updateSkill(skillData: Skill): Promise { const response = await fetch(`${this.baseUrl}/skills`, { method: "PUT", headers: { "Content-Type": "application/json", }, body: JSON.stringify(skillData), }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || "Failed to update skill"); } return response.json(); } static async deleteSkill(skillId: string): Promise { const response = await fetch(`${this.baseUrl}/skills?id=${skillId}`, { method: "DELETE", }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || "Failed to delete skill"); } } // Teams Management static async getTeams(): Promise { const response = await fetch(`${this.baseUrl}/teams`); if (!response.ok) { throw new Error("Failed to fetch teams"); } return response.json(); } static async createTeam( teamData: Omit ): Promise { const response = await fetch(`${this.baseUrl}/teams`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(teamData), }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || "Failed to create team"); } return response.json(); } static async updateTeam(teamData: Team): Promise { const response = await fetch(`${this.baseUrl}/teams`, { method: "PUT", headers: { "Content-Type": "application/json", }, body: JSON.stringify(teamData), }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || "Failed to update team"); } return response.json(); } static async deleteTeam(teamId: string): Promise { const response = await fetch(`${this.baseUrl}/teams?id=${teamId}`, { method: "DELETE", }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || "Failed to delete team"); } } static async deleteDirection(direction: string): Promise { const response = await fetch( `${this.baseUrl}/teams?direction=${encodeURIComponent(direction)}`, { method: "DELETE", } ); if (!response.ok) { const error = await response.json(); throw new Error(error.error || "Failed to delete direction"); } } // Team Members static async getTeamMembers(teamId: string): Promise { const response = await fetch(`${this.baseUrl}/teams/${teamId}/members`); if (!response.ok) { throw new Error("Failed to fetch team members"); } return response.json(); } static async removeTeamMember( teamId: string, memberId: string ): Promise { const response = await fetch(`${this.baseUrl}/teams/${teamId}/members`, { method: "DELETE", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ memberId }), }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || "Failed to remove team member"); } } }