diff --git a/src/migrations/scripts/1640169291421-france-service.ts b/src/migrations/scripts/1640169291421-france-service.ts new file mode 100644 index 0000000000000000000000000000000000000000..09e474dfd3c1865cb6c59e8bb7b0d1aa0db95caa --- /dev/null +++ b/src/migrations/scripts/1640169291421-france-service.ts @@ -0,0 +1,48 @@ +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 == 'labelsQualifications') { + const newDoc = updateText(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 == 'labelsQualifications') { + const newDoc = downgradeText(document); + await db.collection('categoriesothers').updateOne({ _id: document._id }, [{ $set: newDoc }]); + } + } + console.log(`Update done`); +}; + +function updateText(doc) { + doc.modules = doc.modules.filter((elem) => elem.id !== 'maisonFranceService'); + doc.modules.push({ + id: 'maisonFranceService', + text: 'Maison France services', + }); + return doc; +} + +function downgradeText(doc) { + doc.modules = doc.modules.filter((elem) => elem.id !== 'maisonFranceService'); + doc.modules.push({ + id: 'maisonFranceService', + text: 'Maison France Service', + }); + return doc; +}