mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
TxMixin update modify (#2103)
Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
parent
d0f68cc87f
commit
df727de184
@ -175,7 +175,7 @@ export class Hierarchy {
|
|||||||
private txMixin (tx: TxMixin<Doc, Doc>): void {
|
private txMixin (tx: TxMixin<Doc, Doc>): void {
|
||||||
if (this.isDerived(tx.objectClass, core.class.Class)) {
|
if (this.isDerived(tx.objectClass, core.class.Class)) {
|
||||||
const obj = this.getClass(tx.objectId as Ref<Class<Obj>>) as any
|
const obj = this.getClass(tx.objectId as Ref<Class<Obj>>) as any
|
||||||
TxProcessor.updateMixin4Doc(obj, tx.mixin, tx.attributes)
|
TxProcessor.updateMixin4Doc(obj, tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ export class ModelDb extends MemDb implements Storage {
|
|||||||
// TODO: process ancessor mixins
|
// TODO: process ancessor mixins
|
||||||
protected async txMixin (tx: TxMixin<Doc, Doc>): Promise<TxResult> {
|
protected async txMixin (tx: TxMixin<Doc, Doc>): Promise<TxResult> {
|
||||||
const obj = this.getObject(tx.objectId) as any
|
const obj = this.getObject(tx.objectId) as any
|
||||||
TxProcessor.updateMixin4Doc(obj, tx.mixin, tx.attributes)
|
TxProcessor.updateMixin4Doc(obj, tx)
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,14 +274,10 @@ export abstract class TxProcessor implements WithTx {
|
|||||||
return rawDoc
|
return rawDoc
|
||||||
}
|
}
|
||||||
|
|
||||||
static updateMixin4Doc<D extends Doc, M extends D>(
|
static updateMixin4Doc<D extends Doc, M extends D>(rawDoc: D, tx: TxMixin<D, M>): D {
|
||||||
rawDoc: D,
|
const ops = tx.attributes as any
|
||||||
mixinClass: Ref<Class<M>>,
|
|
||||||
operations: MixinUpdate<D, M>
|
|
||||||
): D {
|
|
||||||
const ops = operations as any
|
|
||||||
const doc = _toDoc(rawDoc)
|
const doc = _toDoc(rawDoc)
|
||||||
const mixin = (doc as any)[mixinClass] ?? {}
|
const mixin = (doc as any)[tx.mixin] ?? {}
|
||||||
for (const key in ops) {
|
for (const key in ops) {
|
||||||
if (key.startsWith('$')) {
|
if (key.startsWith('$')) {
|
||||||
const operator = _getOperator(key)
|
const operator = _getOperator(key)
|
||||||
@ -290,7 +286,9 @@ export abstract class TxProcessor implements WithTx {
|
|||||||
mixin[key] = ops[key]
|
mixin[key] = ops[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;(doc as any)[mixinClass] = mixin
|
rawDoc.modifiedBy = tx.modifiedBy
|
||||||
|
rawDoc.modifiedOn = tx.modifiedOn
|
||||||
|
;(doc as any)[tx.mixin] = mixin
|
||||||
return rawDoc
|
return rawDoc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
|||||||
let updatedDoc = q.result.find((p) => p._id === tx.objectId)
|
let updatedDoc = q.result.find((p) => p._id === tx.objectId)
|
||||||
if (updatedDoc !== undefined) {
|
if (updatedDoc !== undefined) {
|
||||||
// Create or apply mixin value
|
// Create or apply mixin value
|
||||||
updatedDoc = TxProcessor.updateMixin4Doc(updatedDoc, tx.mixin, tx.attributes)
|
updatedDoc = TxProcessor.updateMixin4Doc(updatedDoc, tx)
|
||||||
await this.updatedDocCallback(updatedDoc, q)
|
await this.updatedDocCallback(updatedDoc, q)
|
||||||
} else if (isMixin) {
|
} else if (isMixin) {
|
||||||
// Mixin potentially added to object we doesn't have in out results
|
// Mixin potentially added to object we doesn't have in out results
|
||||||
|
@ -310,7 +310,7 @@ class ActivityImpl implements Activity {
|
|||||||
checkMixinState (result: DisplayTx, firstTx: DisplayTx): boolean {
|
checkMixinState (result: DisplayTx, firstTx: DisplayTx): boolean {
|
||||||
if (this.client.getHierarchy().isDerived(result.tx._class, core.class.TxMixin) && result.doc !== undefined) {
|
if (this.client.getHierarchy().isDerived(result.tx._class, core.class.TxMixin) && result.doc !== undefined) {
|
||||||
const mix = result.tx as TxMixin<Doc, Doc>
|
const mix = result.tx as TxMixin<Doc, Doc>
|
||||||
firstTx.doc = TxProcessor.updateMixin4Doc(result.doc, mix.mixin, mix.attributes)
|
firstTx.doc = TxProcessor.updateMixin4Doc(result.doc, mix)
|
||||||
firstTx.mixin = true
|
firstTx.mixin = true
|
||||||
result.mixin = true
|
result.mixin = true
|
||||||
return true
|
return true
|
||||||
|
@ -209,7 +209,7 @@ async function buildRemovedDoc (client: TxOperations, objectId: Ref<Doc>): Promi
|
|||||||
doc = TxProcessor.updateDoc2Doc(doc, tx as TxUpdateDoc<Doc>)
|
doc = TxProcessor.updateDoc2Doc(doc, tx as TxUpdateDoc<Doc>)
|
||||||
} else if (tx._class === core.class.TxMixin) {
|
} else if (tx._class === core.class.TxMixin) {
|
||||||
const mixinTx = tx as TxMixin<Doc, Doc>
|
const mixinTx = tx as TxMixin<Doc, Doc>
|
||||||
doc = TxProcessor.updateMixin4Doc(doc, mixinTx.mixin, mixinTx.attributes)
|
doc = TxProcessor.updateMixin4Doc(doc, mixinTx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return doc
|
return doc
|
||||||
|
@ -290,7 +290,7 @@ class TServerStorage implements ServerStorage {
|
|||||||
doc = TxProcessor.updateDoc2Doc(doc, tx as TxUpdateDoc<Doc>)
|
doc = TxProcessor.updateDoc2Doc(doc, tx as TxUpdateDoc<Doc>)
|
||||||
} else if (tx._class === core.class.TxMixin) {
|
} else if (tx._class === core.class.TxMixin) {
|
||||||
const mixinTx = tx as TxMixin<Doc, Doc>
|
const mixinTx = tx as TxMixin<Doc, Doc>
|
||||||
doc = TxProcessor.updateMixin4Doc(doc, mixinTx.mixin, mixinTx.attributes)
|
doc = TxProcessor.updateMixin4Doc(doc, mixinTx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user