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

feat: migrate null values to 0 for equipments

parent 79f55d01
No related branches found
No related tags found
2 merge requests!104Dev,!98feat: migrate null values to 0 for equipments
import { Db } from 'mongodb';
import { getDb } from '../migrations-utils/db';
export const up = async () => {
const db: Db = await getDb();
const cursor = db.collection('structures').find({});
let document;
while ((document = await cursor.next())) {
const newDoc = document;
if (document.nbComputers === null) {
newDoc.nbComputers = 0;
}
if (document.nbPrinters === null) {
newDoc.nbPrinters = 0;
}
if (document.nbScanners === null) {
newDoc.nbScanners = 0;
}
if (document.nbTablets === null) {
newDoc.nbTablets = 0;
}
if (document.nbNumericTerminal === null) {
newDoc.nbNumericTerminal = 0;
}
await db.collection('structures').updateOne({ _id: document._id }, [{ $set: newDoc }]);
}
console.log(`Update done`);
};
export const down = async () => {
const db: Db = await getDb();
const cursor = db.collection('structures').find({});
let document;
while ((document = await cursor.next())) {
const newDoc = document;
if (document.nbComputers === 0) {
newDoc.nbComputers = null;
}
if (document.nbPrinters === 0) {
newDoc.nbPrinters = null;
}
if (document.nbScanners === 0) {
newDoc.nbScanners = null;
}
if (document.nbTablets === 0) {
newDoc.nbTablets = null;
}
if (document.nbNumericTerminal === 0) {
newDoc.nbNumericTerminal = null;
}
await db.collection('structures').updateOne({ _id: document._id }, [{ $set: newDoc }]);
}
console.log(`Update done`);
};
......@@ -80,11 +80,11 @@ export class ApticStructuresService {
createdStructure.publics = ['toutPublic'];
createdStructure.accountVerified = true;
createdStructure.freeWorkShop = false;
createdStructure.nbComputers = null;
createdStructure.nbPrinters = null;
createdStructure.nbScanners = null;
createdStructure.nbTablets = null;
createdStructure.nbNumericTerminal = null;
createdStructure.nbComputers = 0;
createdStructure.nbPrinters = 0;
createdStructure.nbScanners = 0;
createdStructure.nbTablets = 0;
createdStructure.nbNumericTerminal = 0;
// Address
createdStructure.coord = [structure.address.gpsLng, structure.address.gpsLat];
createdStructure.address = this.formatAddress(structure);
......
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