mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-11 20:27:43 +02:00
WhenFieldChanges trigger (#9913)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -81,7 +81,7 @@ export async function CheckSubProcessesDone (control: ProcessControl, execution:
|
||||
return res === undefined
|
||||
}
|
||||
|
||||
export function OnCardUpdateCheck (
|
||||
export function MatchCardCheck (
|
||||
control: ProcessControl,
|
||||
execution: Execution,
|
||||
params: Record<string, any>,
|
||||
@@ -94,6 +94,23 @@ export function OnCardUpdateCheck (
|
||||
return res.length > 0
|
||||
}
|
||||
|
||||
export function FieldChangedCheck (
|
||||
control: ProcessControl,
|
||||
execution: Execution,
|
||||
params: Record<string, any>,
|
||||
context: Record<string, any>
|
||||
): boolean {
|
||||
if (context.card === undefined) return false
|
||||
const process = control.client.getModel().findObject(execution.process)
|
||||
if (process === undefined) return false
|
||||
if (context.operations === undefined) return false
|
||||
const changedFields = Object.keys(context.operations)
|
||||
const target = Object.keys(params)[0]
|
||||
if (!changedFields.includes(target)) return false
|
||||
const res = matchQuery([context.card], params, process.masterTag, control.client.getHierarchy(), true)
|
||||
return res.length > 0
|
||||
}
|
||||
|
||||
export function CheckTime (control: ProcessControl, execution: Execution, params: Record<string, any>): boolean {
|
||||
if (params.value === undefined) return false
|
||||
return params.value <= Date.now()
|
||||
|
||||
@@ -21,6 +21,7 @@ import core, {
|
||||
Tx,
|
||||
TxCreateDoc,
|
||||
TxCUD,
|
||||
TxMixin,
|
||||
TxProcessor,
|
||||
TxRemoveDoc,
|
||||
TxUpdateDoc
|
||||
@@ -36,7 +37,8 @@ import process, {
|
||||
SelectedExecutionContext,
|
||||
State,
|
||||
Step,
|
||||
Transition
|
||||
Transition,
|
||||
isUpdateTx
|
||||
} from '@hcengineering/process'
|
||||
import { QueueTopic, TriggerControl } from '@hcengineering/server-core'
|
||||
import { ProcessMessage } from '@hcengineering/server-process'
|
||||
@@ -83,9 +85,10 @@ import {
|
||||
AddTag,
|
||||
CheckToDoDone,
|
||||
CheckToDoCancelled,
|
||||
OnCardUpdateCheck,
|
||||
MatchCardCheck,
|
||||
CheckSubProcessesDone,
|
||||
CheckTime
|
||||
CheckTime,
|
||||
FieldChangedCheck
|
||||
} from './functions'
|
||||
import { ToDoCancellRollback, ToDoCloseRollback } from './rollback'
|
||||
|
||||
@@ -258,16 +261,30 @@ export async function OnCardUpdate (txes: Tx[], control: TriggerControl): Promis
|
||||
const res: Tx[] = []
|
||||
for (const tx of txes) {
|
||||
if (!control.hierarchy.isDerived(tx._class, core.class.TxCUD)) continue
|
||||
const cudTx = tx as TxCUD<Card>
|
||||
if (tx._class !== core.class.TxUpdateDoc && tx._class !== core.class.TxMixin) continue
|
||||
const cudTx = tx as TxUpdateDoc<Card> | TxMixin<Card, Card>
|
||||
if (!control.hierarchy.isDerived(cudTx.objectClass, cardPlugin.class.Card)) continue
|
||||
const card = await control.findAll(control.ctx, cardPlugin.class.Card, { _id: cudTx.objectId }, { limit: 1 })
|
||||
if (card.length === 0) continue
|
||||
const ops = isUpdateTx(cudTx) ? cudTx.operations : cudTx.mixin
|
||||
await putEventToQueue(
|
||||
{
|
||||
event: process.trigger.OnCardUpdate,
|
||||
card: cudTx.objectId,
|
||||
context: {
|
||||
card: card[0]
|
||||
card: card[0],
|
||||
operations: ops ?? {}
|
||||
}
|
||||
},
|
||||
control
|
||||
)
|
||||
await putEventToQueue(
|
||||
{
|
||||
event: process.trigger.WhenFieldChanges,
|
||||
card: cudTx.objectId,
|
||||
context: {
|
||||
card: card[0],
|
||||
operations: ops ?? {}
|
||||
}
|
||||
},
|
||||
control
|
||||
@@ -366,7 +383,8 @@ export default async () => ({
|
||||
AddTag,
|
||||
CheckToDoDone,
|
||||
CheckToDoCancelled,
|
||||
OnCardUpdateCheck,
|
||||
FieldChangedCheck,
|
||||
MatchCardCheck,
|
||||
CheckSubProcessesDone,
|
||||
CheckTime
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user