chore: datas are ok and sync also
This commit is contained in:
@@ -63,6 +63,7 @@ export class SkillsService {
|
||||
s.name,
|
||||
s.description,
|
||||
s.icon,
|
||||
s.importance,
|
||||
COALESCE(
|
||||
json_agg(sl.url ORDER BY sl.id) FILTER (WHERE sl.url IS NOT NULL),
|
||||
'[]'::json
|
||||
@@ -70,7 +71,7 @@ export class SkillsService {
|
||||
FROM skills s
|
||||
LEFT JOIN skill_links sl ON s.id = sl.skill_id
|
||||
WHERE s.category_id = $1
|
||||
GROUP BY s.id, s.name, s.description, s.icon
|
||||
GROUP BY s.id, s.name, s.description, s.icon, s.importance
|
||||
ORDER BY s.name
|
||||
`;
|
||||
|
||||
@@ -81,6 +82,7 @@ export class SkillsService {
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
icon: row.icon,
|
||||
importance: row.importance,
|
||||
links: row.links,
|
||||
}));
|
||||
} catch (error) {
|
||||
@@ -121,6 +123,7 @@ export class SkillsService {
|
||||
icon?: string;
|
||||
categoryId: string;
|
||||
links: string[];
|
||||
importance?: string;
|
||||
}): Promise<void> {
|
||||
const pool = getPool();
|
||||
const client = await pool.connect();
|
||||
@@ -130,8 +133,8 @@ export class SkillsService {
|
||||
|
||||
// Insert skill
|
||||
const skillQuery = `
|
||||
INSERT INTO skills (id, name, description, icon, category_id)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
INSERT INTO skills (id, name, description, icon, category_id, importance)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`;
|
||||
await client.query(skillQuery, [
|
||||
skill.id,
|
||||
@@ -139,6 +142,7 @@ export class SkillsService {
|
||||
skill.description,
|
||||
skill.icon,
|
||||
skill.categoryId,
|
||||
skill.importance || "standard",
|
||||
]);
|
||||
|
||||
// Insert links
|
||||
@@ -194,13 +198,14 @@ export class SkillsService {
|
||||
// Insert skills
|
||||
for (const skill of categoryData.skills) {
|
||||
const skillQuery = `
|
||||
INSERT INTO skills (id, name, description, icon, category_id)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
INSERT INTO skills (id, name, description, icon, category_id, importance)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
name = EXCLUDED.name,
|
||||
description = EXCLUDED.description,
|
||||
icon = EXCLUDED.icon,
|
||||
category_id = EXCLUDED.category_id
|
||||
category_id = EXCLUDED.category_id,
|
||||
importance = EXCLUDED.importance
|
||||
`;
|
||||
await client.query(skillQuery, [
|
||||
skill.id,
|
||||
@@ -208,6 +213,7 @@ export class SkillsService {
|
||||
skill.description,
|
||||
skill.icon,
|
||||
categoryId,
|
||||
skill.importance || "standard",
|
||||
]);
|
||||
|
||||
// Delete existing links
|
||||
@@ -324,6 +330,7 @@ export class SkillsService {
|
||||
categoryId: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
importance?: string;
|
||||
}): Promise<{
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -332,6 +339,7 @@ export class SkillsService {
|
||||
categoryId: string;
|
||||
category: string;
|
||||
usageCount: number;
|
||||
importance: string;
|
||||
}> {
|
||||
const pool = getPool();
|
||||
const client = await pool.connect();
|
||||
@@ -351,10 +359,16 @@ export class SkillsService {
|
||||
|
||||
// Créer la nouvelle skill
|
||||
const result = await client.query(
|
||||
`INSERT INTO skills (id, name, category_id, description, icon)
|
||||
VALUES (gen_random_uuid(), $1, $2, $3, $4)
|
||||
RETURNING id, name, description, icon, category_id`,
|
||||
[data.name, data.categoryId, data.description || "", data.icon || ""]
|
||||
`INSERT INTO skills (id, name, category_id, description, icon, importance)
|
||||
VALUES (gen_random_uuid(), $1, $2, $3, $4, $5)
|
||||
RETURNING id, name, description, icon, category_id, importance`,
|
||||
[
|
||||
data.name,
|
||||
data.categoryId,
|
||||
data.description || "",
|
||||
data.icon || "",
|
||||
data.importance || "standard",
|
||||
]
|
||||
);
|
||||
|
||||
const newSkill = result.rows[0];
|
||||
@@ -375,6 +389,7 @@ export class SkillsService {
|
||||
categoryId: newSkill.category_id,
|
||||
category: categoryResult.rows[0]?.name || "Inconnue",
|
||||
usageCount: 0,
|
||||
importance: newSkill.importance,
|
||||
};
|
||||
} catch (error) {
|
||||
await client.query("ROLLBACK");
|
||||
@@ -393,6 +408,7 @@ export class SkillsService {
|
||||
categoryId: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
importance?: string;
|
||||
}): Promise<{
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -400,6 +416,7 @@ export class SkillsService {
|
||||
icon: string;
|
||||
categoryId: string;
|
||||
category: string;
|
||||
importance: string;
|
||||
}> {
|
||||
const pool = getPool();
|
||||
const client = await pool.connect();
|
||||
@@ -430,20 +447,21 @@ export class SkillsService {
|
||||
// Mettre à jour la skill
|
||||
await client.query(
|
||||
`UPDATE skills
|
||||
SET name = $1, category_id = $2, description = $3, icon = $4
|
||||
WHERE id = $5`,
|
||||
SET name = $1, category_id = $2, description = $3, icon = $4, importance = $5
|
||||
WHERE id = $6`,
|
||||
[
|
||||
data.name,
|
||||
data.categoryId,
|
||||
data.description || "",
|
||||
data.icon || "",
|
||||
data.importance || "standard",
|
||||
data.id,
|
||||
]
|
||||
);
|
||||
|
||||
// Récupérer la skill mise à jour
|
||||
const result = await client.query(
|
||||
`SELECT s.id, s.name, s.description, s.icon, s.category_id, sc.name as category_name
|
||||
`SELECT s.id, s.name, s.description, s.icon, s.category_id, sc.name as category_name, s.importance
|
||||
FROM skills s
|
||||
LEFT JOIN skill_categories sc ON s.category_id = sc.id
|
||||
WHERE s.id = $1`,
|
||||
@@ -460,6 +478,7 @@ export class SkillsService {
|
||||
icon: skill.icon,
|
||||
categoryId: skill.category_id,
|
||||
category: skill.category_name,
|
||||
importance: skill.importance,
|
||||
};
|
||||
} catch (error) {
|
||||
await client.query("ROLLBACK");
|
||||
@@ -503,4 +522,4 @@ export class SkillsService {
|
||||
client.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user