diff --git a/packages/core/src/memdb.ts b/packages/core/src/memdb.ts index 832607616d..7842044a3f 100644 --- a/packages/core/src/memdb.ts +++ b/packages/core/src/memdb.ts @@ -211,7 +211,7 @@ export class ModelDb extends MemDb implements Storage { } doc.modifiedBy = tx.modifiedBy doc.modifiedOn = tx.modifiedOn - return { update: 'here' } + return tx.retrieve === true ? { object: doc } : {} } protected async txRemoveDoc (tx: TxRemoveDoc): Promise { diff --git a/packages/core/src/tx.ts b/packages/core/src/tx.ts index 4a86b71cfd..b2a9cd4f28 100644 --- a/packages/core/src/tx.ts +++ b/packages/core/src/tx.ts @@ -155,6 +155,7 @@ export type DocumentUpdate = Partial> & PushOptions & */ export interface TxUpdateDoc extends TxCUD { operations: DocumentUpdate + retrieve?: boolean } /** @@ -273,9 +274,10 @@ export class TxOperations implements Storage { _class: Ref>, space: Ref, objectId: Ref, - operations: DocumentUpdate + operations: DocumentUpdate, + retrieve?: boolean ): Promise { - const tx = this.txFactory.createTxUpdateDoc(_class, space, objectId, operations) + const tx = this.txFactory.createTxUpdateDoc(_class, space, objectId, operations, retrieve) return this.storage.tx(tx) } @@ -346,7 +348,8 @@ export class TxFactory { _class: Ref>, space: Ref, objectId: Ref, - operations: DocumentUpdate + operations: DocumentUpdate, + retrieve?: boolean ): TxUpdateDoc { return { _id: generateId(), @@ -357,7 +360,8 @@ export class TxFactory { objectId, objectClass: _class, objectSpace: space, - operations + operations, + retrieve } } diff --git a/packages/presentation/src/components/AttributeBarEditor.svelte b/packages/presentation/src/components/AttributeBarEditor.svelte index b150a137dc..9f234b422c 100644 --- a/packages/presentation/src/components/AttributeBarEditor.svelte +++ b/packages/presentation/src/components/AttributeBarEditor.svelte @@ -45,7 +45,7 @@ } function onChange(value: any) { - client.updateDoc(_class, object.space, object._id, { [key]: value }).then(result => console.log('UPDATE RESULT', result)) + client.updateDoc(_class, object.space, object._id, { [key]: value }, true).then(result => console.log('UPDATE RESULT', result)) } diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts index 2e05cb96e6..fdc96647e8 100644 --- a/server/mongo/src/storage.ts +++ b/server/mongo/src/storage.ts @@ -179,10 +179,20 @@ class MongoAdapter extends MongoAdapterBase { console.log('ops', ops) return await this.db.collection(domain).bulkWrite(ops as any) } else { - return await this.db.collection(domain).updateOne({ _id: tx.objectId }, tx.operations) + if (tx.retrieve === true) { + const result = await this.db.collection(domain).findOneAndUpdate({ _id: tx.objectId }, tx.operations, { returnDocument: 'after' }) + return { object: result.value } + } else { + return await this.db.collection(domain).updateOne({ _id: tx.objectId }, tx.operations) + } } } else { - return await this.db.collection(domain).updateOne({ _id: tx.objectId }, { $set: tx.operations }) + if (tx.retrieve === true) { + const result = await this.db.collection(domain).findOneAndUpdate({ _id: tx.objectId }, { $set: tx.operations }, { returnDocument: 'after' }) + return { object: result.value } + } else { + return await this.db.collection(domain).updateOne({ _id: tx.objectId }, { $set: tx.operations }) + } } }