mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-10 00:43:23 +00:00
Fix workflow trigger field name mismatch
- Update workflow executor to check both 'collection' and 'collectionSlug' fields - Add debug logging for workflow trigger matching - Fixes issue where collection triggers were not being matched correctly
This commit is contained in:
@@ -606,6 +606,12 @@ export class WorkflowExecutor {
|
|||||||
previousDoc: unknown,
|
previousDoc: unknown,
|
||||||
req: PayloadRequest
|
req: PayloadRequest
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
this.logger.info({
|
||||||
|
collection,
|
||||||
|
operation,
|
||||||
|
docId: (doc as any)?.id
|
||||||
|
}, 'executeTriggeredWorkflows called')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Find workflows with matching triggers
|
// Find workflows with matching triggers
|
||||||
const workflows = await this.payload.find({
|
const workflows = await this.payload.find({
|
||||||
@@ -614,21 +620,46 @@ export class WorkflowExecutor {
|
|||||||
limit: 100,
|
limit: 100,
|
||||||
req
|
req
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.logger.info({
|
||||||
|
workflowCount: workflows.docs.length
|
||||||
|
}, 'Found workflows to check')
|
||||||
|
|
||||||
for (const workflow of workflows.docs) {
|
for (const workflow of workflows.docs) {
|
||||||
// Check if this workflow has a matching trigger
|
// Check if this workflow has a matching trigger
|
||||||
const triggers = workflow.triggers as Array<{
|
const triggers = workflow.triggers as Array<{
|
||||||
collection: string
|
collection?: string
|
||||||
|
collectionSlug?: string
|
||||||
condition?: string
|
condition?: string
|
||||||
operation: string
|
operation: string
|
||||||
type: string
|
type: string
|
||||||
}>
|
}>
|
||||||
|
|
||||||
|
this.logger.debug({
|
||||||
|
workflowId: workflow.id,
|
||||||
|
workflowName: workflow.name,
|
||||||
|
triggerCount: triggers?.length || 0,
|
||||||
|
triggers: triggers?.map(t => ({
|
||||||
|
type: t.type,
|
||||||
|
collection: t.collection,
|
||||||
|
collectionSlug: t.collectionSlug,
|
||||||
|
operation: t.operation
|
||||||
|
}))
|
||||||
|
}, 'Checking workflow triggers')
|
||||||
|
|
||||||
const matchingTriggers = triggers?.filter(trigger =>
|
const matchingTriggers = triggers?.filter(trigger =>
|
||||||
trigger.type === 'collection-trigger' &&
|
trigger.type === 'collection-trigger' &&
|
||||||
trigger.collection === collection &&
|
(trigger.collection === collection || trigger.collectionSlug === collection) &&
|
||||||
trigger.operation === operation
|
trigger.operation === operation
|
||||||
) || []
|
) || []
|
||||||
|
|
||||||
|
this.logger.info({
|
||||||
|
workflowId: workflow.id,
|
||||||
|
workflowName: workflow.name,
|
||||||
|
matchingTriggerCount: matchingTriggers.length,
|
||||||
|
targetCollection: collection,
|
||||||
|
targetOperation: operation
|
||||||
|
}, 'Matching triggers found')
|
||||||
|
|
||||||
for (const trigger of matchingTriggers) {
|
for (const trigger of matchingTriggers) {
|
||||||
// Create execution context for condition evaluation
|
// Create execution context for condition evaluation
|
||||||
|
|||||||
Reference in New Issue
Block a user