mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 03:40:48 +00:00
pass hierarchy
to trigger
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
26c93b9f01
commit
3d833008f5
@ -130,7 +130,7 @@ class TServerStorage implements ServerStorage {
|
||||
// store object
|
||||
await this.routeTx(tx)
|
||||
// invoke triggers and store derived objects
|
||||
const derived = await this.triggers.apply(tx.modifiedBy, tx, this.findAll.bind(this))
|
||||
const derived = await this.triggers.apply(tx.modifiedBy, tx, this.findAll.bind(this), this.hierarchy)
|
||||
for (const tx of derived) {
|
||||
await this.routeTx(tx)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import type { Tx, Doc, TxCreateDoc, Ref, Account } from '@anticrm/core'
|
||||
import type { Tx, Doc, TxCreateDoc, Ref, Account, Hierarchy } from '@anticrm/core'
|
||||
import core, { TxFactory } from '@anticrm/core'
|
||||
|
||||
import { getResource } from '@anticrm/platform'
|
||||
@ -39,8 +39,8 @@ export class Triggers {
|
||||
}
|
||||
}
|
||||
|
||||
async apply (account: Ref<Account>, tx: Tx, findAll: FindAll<Doc>): Promise<Tx[]> {
|
||||
const derived = this.triggers.map(trigger => trigger(tx, new TxFactory(account), findAll))
|
||||
async apply (account: Ref<Account>, tx: Tx, findAll: FindAll<Doc>, hierarchy: Hierarchy): Promise<Tx[]> {
|
||||
const derived = this.triggers.map(trigger => trigger(tx, new TxFactory(account), findAll, hierarchy))
|
||||
const result = await Promise.all(derived)
|
||||
return result.flatMap(x => x)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
//
|
||||
|
||||
import type { Tx, Ref, Doc, Class, Space, Timestamp, Account, FindResult, DocumentQuery, FindOptions } from '@anticrm/core'
|
||||
import { TxFactory } from '@anticrm/core'
|
||||
import { TxFactory, Hierarchy } from '@anticrm/core'
|
||||
import type { Resource } from '@anticrm/platform'
|
||||
|
||||
/**
|
||||
@ -26,7 +26,7 @@ export type FindAll<T extends Doc> = (clazz: Ref<Class<T>>, query: DocumentQuery
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type TriggerFunc = (tx: Tx, txFactory: TxFactory, findAll: FindAll<Doc>) => Promise<Tx[]>
|
||||
export type TriggerFunc = (tx: Tx, txFactory: TxFactory, findAll: FindAll<Doc>, hierarchy: Hierarchy) => Promise<Tx[]>
|
||||
|
||||
/**
|
||||
* @public
|
||||
|
@ -14,23 +14,21 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import type { Tx, TxFactory } from '@anticrm/core'
|
||||
import type { Tx, TxFactory, Doc, TxCreateDoc, DocWithState } from '@anticrm/core'
|
||||
import type { FindAll } from '@anticrm/server-core'
|
||||
|
||||
// import core from '@anticrm/core'
|
||||
import core, { Hierarchy } from '@anticrm/core'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function OnDocWithState (tx: Tx, txFactory: TxFactory): Promise<Tx[]> {
|
||||
// if (tx._class === core.class.TxCreateDoc) {
|
||||
// const createTx = tx as TxCreateDoc<Message>
|
||||
// if (createTx.objectClass === chunter.class.Message) {
|
||||
// const content = createTx.attributes.content
|
||||
// const backlinks = getBacklinks(createTx.objectId, content)
|
||||
// return backlinks.map(backlink => txFactory.createTxCreateDoc(chunter.class.Backlink, chunter.space.Backlinks, backlink))
|
||||
// }
|
||||
// }
|
||||
console.log('OnDocWithState here')
|
||||
export async function OnDocWithState (tx: Tx, txFactory: TxFactory, findAll: FindAll<Doc>, hierarchy: Hierarchy): Promise<Tx[]> {
|
||||
if (tx._class === core.class.TxCreateDoc) {
|
||||
const createTx = tx as TxCreateDoc<DocWithState>
|
||||
if (hierarchy.isDerived(createTx.objectClass, core.class.DocWithState)) {
|
||||
console.log('OnDocWithState derived here')
|
||||
}
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user