Correctif redescente du référentiel

This commit is contained in:
ocroguennec committed 2026-07-04 17:43:57 +02:00
1 parent ff77ee977d
commit 69d006d358
7 files changed
+82 -43

No files matched your search

+12 -7
View File
@@ -825,7 +825,7 @@ router.post('/:id/push', (req, res, next) => {
).all(ref.id).map(r => r.secteur_id);
const plateformes = db.prepare(
'SELECT id, overridden_fields FROM plateformes WHERE referentiel_id = ?'
'SELECT id, overridden_fields, excluded_categories_inv_ids, excluded_secteurs_inv_ids FROM plateformes WHERE referentiel_id = ?'
).all(ref.id);
let nb_updated = 0;
@@ -853,14 +853,19 @@ router.post('/:id/push', (req, res, next) => {
}
// ── Catégories/secteurs ──
// Méthode dure (force) : réinitialise aussi les exclusions utilisateur et remplace toutes les associations.
// Méthode douce (défaut) : respecte les tags que l'utilisateur a explicitement retirés (excluded_*_ids).
const excludedCatIds = force ? new Set() : new Set(JSON.parse(plat.excluded_categories_inv_ids || '[]'));
const excludedSectIds = force ? new Set() : new Set(JSON.parse(plat.excluded_secteurs_inv_ids || '[]'));
if (force) {
// Méthode dure : remplace toutes les associations
db.prepare('DELETE FROM plateforme_categories_inv WHERE plateforme_id = ?').run(plat.id);
db.prepare('DELETE FROM plateforme_secteurs_inv WHERE plateforme_id = ?').run(plat.id);
db.prepare("UPDATE plateformes SET excluded_categories_inv_ids = '[]', excluded_secteurs_inv_ids = '[]' WHERE id = ?").run(plat.id);
}
// Méthode douce : INSERT OR IGNORE (n'écrase pas les associations existantes)
for (const catId of refCatIds) insCat.run(plat.id, catId);
for (const sectId of refSectIds) insSect.run(plat.id, sectId);
// INSERT OR IGNORE (n'écrase pas les associations existantes), en sautant les tags exclus par l'utilisateur
for (const catId of refCatIds) if (!excludedCatIds.has(catId)) insCat.run(plat.id, catId);
for (const sectId of refSectIds) if (!excludedSectIds.has(sectId)) insSect.run(plat.id, sectId);
// Sync investissements actifs de la plateforme
const invs = db.prepare(
@@ -871,8 +876,8 @@ router.post('/:id/push', (req, res, next) => {
db.prepare('DELETE FROM investissement_categories_inv WHERE investissement_id = ?').run(inv.id);
db.prepare('DELETE FROM investissement_secteurs_inv WHERE investissement_id = ?').run(inv.id);
}
for (const catId of refCatIds) insInvCat.run(inv.id, catId);
for (const sectId of refSectIds) insInvSect.run(inv.id, sectId);
for (const catId of refCatIds) if (!excludedCatIds.has(catId)) insInvCat.run(inv.id, catId);
for (const sectId of refSectIds) if (!excludedSectIds.has(sectId)) insInvSect.run(inv.id, sectId);
}
nb_updated++;