-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correction de l'api de mise a jour de reseau + migration
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
server/src/db/migrations/20250305140803-change-key-name-reseau.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { addJob } from "job-processor"; | ||
|
||
import { organismesDb, reseauxDb } from "@/common/model/collections"; | ||
|
||
export const up = async () => { | ||
// Récupération de tous les reseaux des organismes, et vérification si c'est le nom ou le key qui est dans la liste | ||
// Puis mise à jour en conséquence | ||
|
||
const allReseaux = await reseauxDb().find().toArray(); | ||
|
||
const reseauxMap = allReseaux.reduce((acc, curr) => { | ||
return { | ||
...acc, | ||
[curr.nom]: curr.key, | ||
}; | ||
}, {}); | ||
|
||
const cursor = organismesDb().find({ reseaux: { $exists: true, $not: { $size: 0 } } }); | ||
while (await cursor.hasNext()) { | ||
const org = await cursor.next(); | ||
if (org) { | ||
// Remplacer le nom par la key si existe, sinon on garde la valeur dans la liste | ||
const newReseaux = org?.reseaux?.map((n) => reseauxMap[n] ?? n); | ||
await organismesDb().updateOne({ _id: org._id }, { $set: { reseaux: newReseaux } }); | ||
} | ||
} | ||
// Mise a jour des computed des organismes | ||
await addJob({ name: "computed:update", queued: true }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters