mirror of
https://github.com/hcengineering/platform.git
synced 2025-02-02 17:02:29 +00:00
fix mongo
$inc operator
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
75c90a3d6c
commit
a5ccda96c4
@ -78,6 +78,15 @@ const operators: Record<string, _OperatorFunc> = {
|
||||
$inc
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export function isOperator (o: Record<string, any>): boolean {
|
||||
if (o === null || typeof o !== 'object') { return false }
|
||||
const keys = Object.keys(o)
|
||||
return keys.length > 0 && keys.every((key) => key.startsWith('$'))
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param name -
|
||||
|
@ -13,7 +13,8 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import core, { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxCreateDoc, TxUpdateDoc, TxMixin, TxPutBag, TxRemoveDoc, TxProcessor, Hierarchy, DOMAIN_TX, SortingOrder } from '@anticrm/core'
|
||||
import type { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxCreateDoc, TxUpdateDoc, TxMixin, TxPutBag, TxRemoveDoc } from '@anticrm/core'
|
||||
import core, { DOMAIN_TX, SortingOrder, TxProcessor, Hierarchy, isOperator } from '@anticrm/core'
|
||||
|
||||
import type { DbAdapter, TxAdapter } from '@anticrm/server-core'
|
||||
|
||||
@ -114,7 +115,8 @@ class MongoAdapter extends MongoAdapterBase {
|
||||
|
||||
protected override async txUpdateDoc (tx: TxUpdateDoc<Doc>): Promise<void> {
|
||||
const domain = this.hierarchy.getDomain(tx.objectClass)
|
||||
await this.db.collection(domain).updateOne({ _id: tx.objectId }, { $set: tx.operations })
|
||||
const op = isOperator(tx.operations) ? tx.operations : { $set: tx.operations }
|
||||
await this.db.collection(domain).updateOne({ _id: tx.objectId }, op)
|
||||
}
|
||||
|
||||
override tx (tx: Tx): Promise<void> {
|
||||
|
Loading…
Reference in New Issue
Block a user