feat: CRUD admin for skills and teams
This commit is contained in:
146
services/admin-management-service.ts
Normal file
146
services/admin-management-service.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
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 class AdminManagementService {
|
||||
private static baseUrl = "/api/admin";
|
||||
|
||||
// Skills Management
|
||||
static async getSkills(): Promise<Skill[]> {
|
||||
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<Skill, "id" | "usageCount">
|
||||
): Promise<Skill> {
|
||||
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<Skill> {
|
||||
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<void> {
|
||||
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<Team[]> {
|
||||
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<Team, "id" | "memberCount">
|
||||
): Promise<Team> {
|
||||
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<Team> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,8 @@ export { SkillsService } from "./skills-service";
|
||||
// Admin services (server-only)
|
||||
export { AdminService } from "./admin-service";
|
||||
|
||||
// Admin management services (client-side compatible)
|
||||
export { AdminManagementService } from "./admin-management-service";
|
||||
|
||||
// API client (can be used client-side)
|
||||
export { ApiClient, apiClient } from "./api-client";
|
||||
|
||||
Reference in New Issue
Block a user