From 246e3486f0e46d0814520c5b21f90dd61151b684 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 11 Sep 2019 12:12:50 +0200 Subject: [PATCH] fix(id field now properly populated): update --- test/test.ts | 5 ++++- ts/smartdata.classes.collection.ts | 2 +- ts/smartdata.classes.doc.ts | 6 ++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/test.ts b/test/test.ts index 990641f..68a51d1 100644 --- a/test/test.ts +++ b/test/test.ts @@ -136,7 +136,10 @@ tap.test('should store a new Truck', async () => { const truck = new Truck('blue', 'MAN'); await truck.save(); const myTruck = await Truck.getInstance({color: 'blue'}); - console.log(myTruck); + myTruck.id = 'foo'; + await myTruck.save(); + const myTruck2 = await Truck.getInstance({color: 'blue'}); + console.log(myTruck2); }); diff --git a/ts/smartdata.classes.collection.ts b/ts/smartdata.classes.collection.ts index aa96e64..f7b3763 100644 --- a/ts/smartdata.classes.collection.ts +++ b/ts/smartdata.classes.collection.ts @@ -141,7 +141,7 @@ export class SmartdataCollection { await this.init(); await this.checkDoc(dbDocArg); const identifiableObject = await dbDocArg.createIdentifiableObject(); - this.mongoDbCollection.deleteOne(identifiableObject); + await this.mongoDbCollection.deleteOne(identifiableObject); } /** diff --git a/ts/smartdata.classes.doc.ts b/ts/smartdata.classes.doc.ts index 7f855ad..456f10c 100644 --- a/ts/smartdata.classes.doc.ts +++ b/ts/smartdata.classes.doc.ts @@ -103,10 +103,8 @@ export class SmartDataDbDoc { for (const item of foundDocs) { const newInstance = new this(); newInstance.creationStatus = 'db'; - for (const key in item) { - if (key !== 'id') { - newInstance[key] = item[key]; - } + for (const key of Object.keys(item)) { + newInstance[key] = item[key]; } returnArray.push(newInstance); }