mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-13 05:07:43 +02:00
feat: add OnExecutionDone trigger and related functionality for proce… (#10944)
* feat: add OnExecutionDone trigger and related functionality for process management Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com> * Fix Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com> --------- Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -52,6 +52,7 @@ import process, {
|
||||
} from '@hcengineering/process'
|
||||
import { QueueTopic, TriggerControl } from '@hcengineering/server-core'
|
||||
import { ProcessMessage } from '@hcengineering/server-process'
|
||||
import time from '@hcengineering/time'
|
||||
import {
|
||||
AddRelation,
|
||||
AddTag,
|
||||
@@ -304,6 +305,34 @@ export async function OnExecutionContinue (txes: Tx[], control: TriggerControl):
|
||||
return []
|
||||
}
|
||||
|
||||
export async function OnExecutionDone (txes: Tx[], control: TriggerControl): Promise<Tx[]> {
|
||||
const res: Tx[] = []
|
||||
for (const tx of txes) {
|
||||
if (tx._class !== core.class.TxUpdateDoc) continue
|
||||
if (tx.space !== core.space.Tx) continue
|
||||
const updateTx = tx as TxUpdateDoc<Execution>
|
||||
if (!control.hierarchy.isDerived(updateTx.objectClass, process.class.Execution)) continue
|
||||
if (updateTx.operations.status !== ExecutionStatus.Done) continue
|
||||
|
||||
const todos = await control.findAll(control.ctx, process.class.ProcessToDo, {
|
||||
execution: updateTx.objectId,
|
||||
doneOn: null
|
||||
})
|
||||
if (todos.length === 0) continue
|
||||
|
||||
const workslots = await control.findAll(control.ctx, time.class.WorkSlot, {
|
||||
attachedTo: { $in: todos.map((todo) => todo._id) }
|
||||
})
|
||||
const todosWithWorkslots = new Set(workslots.map((workslot) => workslot.attachedTo as string))
|
||||
|
||||
for (const todo of todos) {
|
||||
if (todosWithWorkslots.has(todo._id as string)) continue
|
||||
res.push(control.txFactory.createTxRemoveDoc(todo._class, todo.space, todo._id))
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
export async function OnProcessRemove (txes: Tx[], control: TriggerControl): Promise<Tx[]> {
|
||||
const res: Tx[] = []
|
||||
for (const tx of txes) {
|
||||
@@ -825,6 +854,7 @@ export default async () => ({
|
||||
OnProcessToDoClose,
|
||||
OnProcessToDoRemove,
|
||||
OnExecutionContinue,
|
||||
OnExecutionDone,
|
||||
OnCustomEvent,
|
||||
OnExecutionRemove,
|
||||
OnCardCreate,
|
||||
|
||||
Reference in New Issue
Block a user