fix(workflow-engine-*): q text search (#12435)

This commit is contained in:
Adrien de Peretti
2025-05-11 16:21:41 +02:00
committed by GitHub
parent e4d196e522
commit 9d29078b0d
6 changed files with 237 additions and 5 deletions

View File

@@ -1,12 +1,16 @@
import {
Context,
DAL,
FilterableWorkflowExecutionProps,
FindConfig,
InferEntityType,
InternalModuleDeclaration,
ModulesSdkTypes,
WorkflowExecutionDTO,
WorkflowsSdkTypes,
} from "@medusajs/framework/types"
import {
InjectManager,
InjectSharedContext,
isDefined,
MedusaContext,
@@ -74,6 +78,68 @@ export class WorkflowsModuleService<
},
}
static prepareFilters<T>(filters: T & { q?: string }) {
const filters_ = { ...filters } // shallow copy
if (filters_?.q) {
const q = filters_.q
delete filters_.q
const textSearch = { $ilike: `%${q}%` }
const textSearchFilters = {
$or: [
{
transaction_id: textSearch,
},
{
workflow_id: textSearch,
},
{
state: textSearch,
},
{
execution: {
runId: textSearch,
},
},
],
}
if (!Object.keys(filters_).length) {
return textSearchFilters
} else {
return { $and: [filters, textSearchFilters] }
}
}
return filters
}
@InjectManager()
// @ts-expect-error
async listWorkflowExecutions(
filters: FilterableWorkflowExecutionProps = {},
config?: FindConfig<WorkflowExecutionDTO>,
@MedusaContext() sharedContext?: Context
) {
const filters_ = WorkflowsModuleService.prepareFilters(filters)
return await super.listWorkflowExecutions(filters_, config, sharedContext)
}
@InjectManager()
// @ts-expect-error
async listAndCountWorkflowExecutions(
filters: FilterableWorkflowExecutionProps = {},
config?: FindConfig<WorkflowExecutionDTO>,
@MedusaContext() sharedContext?: Context
) {
const filters_ = WorkflowsModuleService.prepareFilters(filters)
return await super.listAndCountWorkflowExecutions(
filters_,
config,
sharedContext
)
}
@InjectSharedContext()
async run<TWorkflow extends string | ReturnWorkflow<any, any, any>>(
workflowIdOrWorkflow: TWorkflow,

View File

@@ -1,12 +1,16 @@
import {
Context,
DAL,
FilterableWorkflowExecutionProps,
FindConfig,
InferEntityType,
InternalModuleDeclaration,
ModulesSdkTypes,
WorkflowExecutionDTO,
WorkflowsSdkTypes,
} from "@medusajs/framework/types"
import {
InjectManager,
InjectSharedContext,
isDefined,
MedusaContext,
@@ -86,6 +90,68 @@ export class WorkflowsModuleService<
},
}
static prepareFilters<T>(filters: T & { q?: string }) {
const filters_ = { ...filters } // shallow copy
if (filters_?.q) {
const q = filters_.q
delete filters_.q
const textSearch = { $ilike: `%${q}%` }
const textSearchFilters = {
$or: [
{
transaction_id: textSearch,
},
{
workflow_id: textSearch,
},
{
state: textSearch,
},
{
execution: {
runId: textSearch,
},
},
],
}
if (!Object.keys(filters_).length) {
return textSearchFilters
} else {
return { $and: [filters, textSearchFilters] }
}
}
return filters
}
@InjectManager()
// @ts-expect-error
async listWorkflowExecutions(
filters: FilterableWorkflowExecutionProps = {},
config?: FindConfig<WorkflowExecutionDTO>,
@MedusaContext() sharedContext?: Context
) {
const filters_ = WorkflowsModuleService.prepareFilters(filters)
return await super.listWorkflowExecutions(filters_, config, sharedContext)
}
@InjectManager()
// @ts-expect-error
async listAndCountWorkflowExecutions(
filters: FilterableWorkflowExecutionProps = {},
config?: FindConfig<WorkflowExecutionDTO>,
@MedusaContext() sharedContext?: Context
) {
const filters_ = WorkflowsModuleService.prepareFilters(filters)
return await super.listAndCountWorkflowExecutions(
filters_,
config,
sharedContext
)
}
@InjectSharedContext()
async run<TWorkflow extends string | ReturnWorkflow<any, any, any>>(
workflowIdOrWorkflow: TWorkflow,