diff --git a/src/migrations/scripts/1640095148120-remove-equipments-null-values.ts b/src/migrations/scripts/1640095148120-remove-equipments-null-values.ts new file mode 100644 index 0000000000000000000000000000000000000000..400d666b2fca7e362e0ef725da32cdfc0aff521c --- /dev/null +++ b/src/migrations/scripts/1640095148120-remove-equipments-null-values.ts @@ -0,0 +1,56 @@ +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`); +}; diff --git a/src/structures/services/aptic-structures.service.ts b/src/structures/services/aptic-structures.service.ts index 766a7513fbdfe2cfeb5c88a2d6d86de0acdebbd4..1833e57fbba23f4a35b652fe641eb9ae60ef7547 100644 --- a/src/structures/services/aptic-structures.service.ts +++ b/src/structures/services/aptic-structures.service.ts @@ -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);