refactor: SSR on skills management

This commit is contained in:
Julien Froidefond
2025-08-25 09:04:33 +02:00
parent e02af4f992
commit 0c7903bcb2
6 changed files with 51 additions and 52 deletions

View File

@@ -1,6 +1,7 @@
import { getPool } from "./database";
import { Team, SkillCategory } from "@/lib/types";
import { TeamMember, TeamStats, DirectionStats } from "@/lib/admin-types";
import { SkillsService } from "./skills-service";
export class AdminService {
/**
@@ -197,18 +198,23 @@ export class AdminService {
skillCategories: SkillCategory[];
teamStats: TeamStats[];
directionStats: DirectionStats[];
skills: any[];
}> {
const pool = getPool();
try {
// Récupérer toutes les données en parallèle
const [teamsResult, categoriesResult, teamStats] = await Promise.all([
pool.query(
"SELECT id, name, direction FROM teams ORDER BY direction, name"
),
pool.query("SELECT id, name, icon FROM skill_categories ORDER BY name"),
AdminService.getTeamsStats(),
]);
const [teamsResult, categoriesResult, teamStats, skills] =
await Promise.all([
pool.query(
"SELECT id, name, direction FROM teams ORDER BY direction, name"
),
pool.query(
"SELECT id, name, icon FROM skill_categories ORDER BY name"
),
AdminService.getTeamsStats(),
SkillsService.getAllSkillsWithUsage(),
]);
const teams = teamsResult.rows;
const skillCategories = categoriesResult.rows.map((row) => ({
@@ -224,6 +230,7 @@ export class AdminService {
skillCategories,
teamStats,
directionStats,
skills,
};
} catch (error) {
console.error("Error fetching admin data:", error);