From fc5ec6d0bd2e7b66b6cad64b82eb9e04517f3511 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Fri, 25 Mar 2022 18:44:14 +0300 Subject: [PATCH 1/2] Migration for converting null notes to empty array --- migration.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/migration.js b/migration.js index 6c5acde..dbabb31 100644 --- a/migration.js +++ b/migration.js @@ -51,9 +51,22 @@ async function fixNullEvents() { } } +async function fixNullNotes() { + let client = await MongoClient.connect(process.env.MONGO_CONNECTION_STRING, { useUnifiedTopology: true }); + let db = client.db('autocatdev'); + let collection = db.collection('vehicles'); + let vehicles = await collection.find().toArray(); + for(let vehicle of vehicles) { + if(vehicle.notes == null) { + //console.log(vehicle.events); + await collection.updateOne({ number: vehicle.number }, { $set: { notes: [] } }); + } + } +} + (async () => { //await addUpdatedDate(); //await addDebugInfoStatus(); - await fixNullEvents(); + await fixNullNotes(); console.log('====== Done ======'); })(); From 1de3d76a9f1787701bdba7a992df01055c801249 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Tue, 19 Apr 2022 15:23:03 +0300 Subject: [PATCH 2/2] Fixed error when name could not be found --- routes/vehicles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/vehicles.js b/routes/vehicles.js index 6bffa47..c4e7ff8 100644 --- a/routes/vehicles.js +++ b/routes/vehicles.js @@ -75,7 +75,7 @@ router.post('/check', async (req, res) => { } else if(autocod.status == 'rejected') { vehicle = vin01.value; Object.assign(vehicle.debugInfo, autocod.reason.debugInfo); - if(!vehicle.brand.name.normalized) { + if(!vehicle.brand?.name?.normalized) { throw autocod.reason; } } else {