diff --git a/src/migrations/scripts/1639062602934-solidarity-sell-service.ts b/src/migrations/scripts/1639062602934-solidarity-sell-service.ts new file mode 100644 index 0000000000000000000000000000000000000000..5ca327c19a617f2ff60c0c7241743df4da1ae071 --- /dev/null +++ b/src/migrations/scripts/1639062602934-solidarity-sell-service.ts @@ -0,0 +1,49 @@ +import { Db } from 'mongodb'; +import { getDb } from '../migrations-utils/db'; + +export const up = async () => { + const db: Db = await getDb(); + + const cursor = db.collection('categoriesothers').find({}); + let document; + while ((document = await cursor.next())) { + if (document.id == 'equipmentsAndServices') { + const newDoc = updateLabel(document); + await db.collection('categoriesothers').updateOne({ _id: document._id }, [{ $set: newDoc }]); + } + } + console.log(`Update done`); +}; + +export const down = async () => { + const db: Db = await getDb(); + + const cursor = db.collection('categoriesothers').find({}); + let document; + while ((document = await cursor.next())) { + if (document.id == 'equipmentsAndServices') { + const newDoc = downgradeLabel(document); + await db.collection('categoriesothers').updateOne({ _id: document._id }, [{ $set: newDoc }]); + } + } + console.log(`Update done`); +}; + +function updateLabel(doc) { + if (doc.modules) { + doc.modules.push({ + id: 'venteMaterielPrixSolidaire', + text: 'Vente de matériel à prix solidaire', + }); + } + return doc; +} + +function downgradeLabel(doc) { + if (doc.modules) { + doc.modules = doc.modules.filter(function (elem) { + return elem.id != 'venteMaterielPrixSolidaire'; + }); + } + return doc; +}