Skip to content
Snippets Groups Projects
Commit f5544fd0 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

Merge branch 'feat/pix-label' into 'dev'

feat: add migration for pix label

See merge request web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server!81
parents 274e3f54 ab52515c
No related branches found
No related tags found
3 merge requests!96release V1.10.0,!83Dev,!81feat: add migration for pix label
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 = 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 == 'labelsQualification') {
const newDoc = downgradeLabel(document);
await db.collection('categoriesothers').updateOne({ _id: document._id }, [{ $set: newDoc }]);
}
}
console.log(`Update done`);
};
function updateLabel(doc) {
doc = addPix(doc);
return doc;
}
function downgradeLabel(doc) {
doc = removePix(doc);
return doc;
}
function removePix(doc) {
if (doc.modules) {
doc.modules = doc.modules.filter(function (elem) {
return elem.id != 'pix';
});
}
return doc;
}
function addPix(doc) {
if (doc.modules) {
doc.modules.push({
id: 'pix',
text: 'Évaluation des compétences numériques',
});
}
return doc;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment