Skip to content
Snippets Groups Projects

feat: add women to public list

Merged Antonin COQUET requested to merge feat/add-women-public into dev
1 file
+ 59
0
Compare changes
  • Side-by-side
  • Inline
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 == 'publics') {
const newDoc = updatePublic(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 == 'publics') {
const newDoc = downgradePublic(document);
await db.collection('categoriesothers').updateOne({ _id: document._id }, [{ $set: newDoc }]);
}
}
console.log(`Update done`);
};
function updatePublic(doc) {
doc = addWomen(doc);
return doc;
}
function downgradePublic(doc) {
doc = removeWomen(doc);
return doc;
}
function removeWomen(doc) {
if (doc.modules) {
doc.modules = doc.modules.filter(function (elem) {
return elem.id != 'women';
});
}
return doc;
}
function addWomen(doc) {
if (doc.modules) {
doc.modules.push({
id: 'women',
text: 'Femmes',
});
}
return doc;
}
Loading