Skip to content

Commit

Permalink
feat(api): merci victor
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmeunier committed Oct 17, 2023
1 parent 2f12f2a commit 8cf63ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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");
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8cf63ae

Please sign in to comment.