From 650d5da6c2b51ec7472a459fae84144625d281bf Mon Sep 17 00:00:00 2001 From: Christophe Cadilhac Date: Thu, 17 Oct 2024 17:43:16 +0200 Subject: [PATCH] =?UTF-8?q?Ajoute=20une=20`ConsoleAdministration`=20permet?= =?UTF-8?q?tant=20l'ex=C3=A9cution=20d'op=C3=A9rations=20d'admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On va commencer par la regénération de tous les événements Metabase pour y inclure l'éligibilité. --- anssi-nis2-api/src/consoleAdministration.ts | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 anssi-nis2-api/src/consoleAdministration.ts diff --git a/anssi-nis2-api/src/consoleAdministration.ts b/anssi-nis2-api/src/consoleAdministration.ts new file mode 100644 index 00000000..e450d319 --- /dev/null +++ b/anssi-nis2-api/src/consoleAdministration.ts @@ -0,0 +1,34 @@ +import * as Knex from "knex"; +import * as configurationKnex from "../knexfile"; +import { AdaptateurJournalPostgres } from "./adaptateurs/adaptateurJournal.postgres"; +import { AdaptateurEligibiliteCsv } from "./adaptateurs/adaptateurEligibilite.csv"; + +export class ConsoleAdministration { + constructor( + private readonly adaptateurJournal = new AdaptateurJournalPostgres(), + private readonly adaptateurEligibilite = new AdaptateurEligibiliteCsv(), + private readonly knexPersistance: Knex.Knex = Knex(configurationKnex), + ) {} + + public async genereTousEvenementsQuestionnaire() { + const reponses = await this.knexPersistance("simulateur_reponse").select(); + + const succes = []; + const erreurs = []; + + reponses.map(({ id, reponseJson }) => { + try { + const resultat = + this.adaptateurEligibilite.evalueEligibilite(reponseJson); + succes.push(resultat); + } catch (e) { + erreurs.push({ erreur: e, id: id }); + } + }); + + console.log(erreurs); + + console.log("-----------"); + console.log(`RÉSUMÉ : ✅ ${succes.length}. 💥 ${erreurs.length}.`); + } +}