mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-25 01:39:53 +00:00
retrieve option for TxUpdate
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
002af26680
commit
8013bc086c
@ -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<Doc>): Promise<TxResult> {
|
||||
|
@ -155,6 +155,7 @@ export type DocumentUpdate<T extends Doc> = Partial<Data<T>> & PushOptions<T> &
|
||||
*/
|
||||
export interface TxUpdateDoc<T extends Doc> extends TxCUD<T> {
|
||||
operations: DocumentUpdate<T>
|
||||
retrieve?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@ -273,9 +274,10 @@ export class TxOperations implements Storage {
|
||||
_class: Ref<Class<T>>,
|
||||
space: Ref<Space>,
|
||||
objectId: Ref<T>,
|
||||
operations: DocumentUpdate<T>
|
||||
operations: DocumentUpdate<T>,
|
||||
retrieve?: boolean
|
||||
): Promise<TxResult> {
|
||||
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<Class<T>>,
|
||||
space: Ref<Space>,
|
||||
objectId: Ref<T>,
|
||||
operations: DocumentUpdate<T>
|
||||
operations: DocumentUpdate<T>,
|
||||
retrieve?: boolean
|
||||
): TxUpdateDoc<T> {
|
||||
return {
|
||||
_id: generateId(),
|
||||
@ -357,7 +360,8 @@ export class TxFactory {
|
||||
objectId,
|
||||
objectClass: _class,
|
||||
objectSpace: space,
|
||||
operations
|
||||
operations,
|
||||
retrieve
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user