fix(workflow-engine-*): q text search (#12435)
This commit is contained in:
1 parent
e4d196e522
commit
9d29078b0d
6 files changed
+237
-5
No files matched your search
@@ -1,6 +1,10 @@
|
||||
import { FindParams } from "../../common"
|
||||
|
||||
export interface AdminGetWorkflowExecutionsParams extends FindParams {
|
||||
/**
|
||||
* Filter using a search query.
|
||||
*/
|
||||
q?: string
|
||||
/**
|
||||
* Filter by the ID of the transaction to retrieve workflow executions for a specific transaction.
|
||||
*/
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { BaseFilterable, OperatorMap } from "../dal"
|
||||
|
||||
import { TransactionState } from "../http"
|
||||
export interface WorkflowExecutionDTO {
|
||||
id: string
|
||||
workflow_id: string
|
||||
transaction_id: string
|
||||
execution: string
|
||||
context: string
|
||||
state: any
|
||||
execution: Record<string, any> | null
|
||||
context: Record<string, any> | null
|
||||
state: TransactionState
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
deleted_at: Date
|
||||
deleted_at: Date | null
|
||||
}
|
||||
|
||||
export interface FilterableWorkflowExecutionProps
|
||||
extends BaseFilterable<FilterableWorkflowExecutionProps> {
|
||||
q?: string
|
||||
id?: string | string[] | OperatorMap<string>
|
||||
workflow_id?: string | string[] | OperatorMap<string>
|
||||
transaction_id?: string | string[] | OperatorMap<string>
|
||||
|
||||
@@ -16,6 +16,7 @@ export const AdminGetWorkflowExecutionsParams = createFindParams({
|
||||
limit: 100,
|
||||
}).merge(
|
||||
z.object({
|
||||
q: z.string().optional(),
|
||||
transaction_id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
workflow_id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user