From 8cf63ae036ff93f6f86423cb8d3b0d613bc2af38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20Silv=C3=A8re=20Meunier?= Date: Tue, 17 Oct 2023 16:18:47 +0200 Subject: [PATCH] feat(api): merci victor --- ...0928101239-add-bop-to-fonjep-versements.js | 31 +++++++++---------- .../providers/fonjep/joiners/fonjepJoiner.ts | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/api/migrations/20230928101239-add-bop-to-fonjep-versements.js b/packages/api/migrations/20230928101239-add-bop-to-fonjep-versements.js index 14fc8bc8d..a3668c002 100644 --- a/packages/api/migrations/20230928101239-add-bop-to-fonjep-versements.js +++ b/packages/api/migrations/20230928101239-add-bop-to-fonjep-versements.js @@ -1,29 +1,28 @@ const { default: fonjepService } = require("../build/src/modules/providers/fonjep/fonjep.service"); -const { default: fonjepJoiner } = require("../build/src/modules/providers/fonjep/joiners/fonjepJoiner"); module.exports = { async up(db) { - const fullGrants = await fonjepJoiner.getAllFullGrants(); + const result = await db + .collection("fonjepSubvention") + .aggregate([ + { $match: {} }, + { + $group: { + _id: "$data.Dispositif.FinanceurCode", + subs: { $addToSet: "$indexedInformations.code_poste" }, + }, + }, + ]) + .toArray(); - const versementsGroupByFinanceurCode = fullGrants.reduce((acc, curr) => { - const financeurCode = curr.data.Dispositif.FinanceurCode; - if (!acc[financeurCode]) acc[financeurCode] = curr.payments; - else acc[financeurCode].push(...curr.payments); - return acc; - }, {}); - - for (const [versements, code] of versementsGroupByFinanceurCode) { - const bop = fonjepService.getBopFromFounderCode(code); - console.log(`start update versements with bop ${bop}`); + for (const obj of result) { + const bop = fonjepService.getBopFromFounderCode(obj._id); await db .collection("fonjepVersement") .updateMany( - { _id: { $in: versements.map(versement => versement._id) } }, + { "indexedInformations.code_poste": { $in: obj.subs } }, { $set: { "indexedInformations.bop": bop } }, ); - console.log(`end update versements with bop ${bop}`); } - - throw new Error("end mig"); }, }; diff --git a/packages/api/src/modules/providers/fonjep/joiners/fonjepJoiner.ts b/packages/api/src/modules/providers/fonjep/joiners/fonjepJoiner.ts index 6250b773e..50b9bb46c 100644 --- a/packages/api/src/modules/providers/fonjep/joiners/fonjepJoiner.ts +++ b/packages/api/src/modules/providers/fonjep/joiners/fonjepJoiner.ts @@ -33,7 +33,7 @@ export class FonjepJoiner { } public getAllFullGrants() { - return this.applicationCollection.aggregate([{ $match: {} }, ...this.joinPipeline]).toArray(); + return this.applicationCollection.aggregate([{ $match: {} }, ...this.joinPipeline]); } public getFullFonjepGrantsBySiret(siret: Siret) {