-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update listWorkflows route handler to list archived workflows (#766)
Add field "listType" to listWorkflows route handler to choose between listing regular workflows or listing archived workflows Modify schema to enforce required fields for the archival use case Change time filters to use ISO string instead of ns timestamp
- Loading branch information
1 parent
b68d1bb
commit bb5b60a
Showing
6 changed files
with
85 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 50 additions & 30 deletions
80
src/route-handlers/list-workflows/schemas/list-workflows-query-params-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,58 @@ | ||
import { z } from 'zod'; | ||
|
||
import getTimestampNsFromISO from '@/utils/datetime/get-timestamp-ns-from-iso'; | ||
import { SORT_ORDERS } from '@/utils/sort-by'; | ||
import isWorkflowStatus from '@/views/shared/workflow-status-tag/helpers/is-workflow-status'; | ||
import { type WorkflowStatus } from '@/views/shared/workflow-status-tag/workflow-status-tag.types'; | ||
|
||
const listWorkflowsQueryParamSchema = z.object({ | ||
pageSize: z | ||
.string() | ||
.transform((val) => parseInt(val, 10)) | ||
.pipe( | ||
z.number().positive({ message: 'Page size must be a positive integer' }) | ||
), | ||
inputType: z.enum(['search', 'query']), | ||
search: z.string().optional(), | ||
query: z.string().optional(), | ||
status: z | ||
.custom<WorkflowStatus>(isWorkflowStatus, { | ||
message: 'Invalid workflow status', | ||
}) | ||
.optional(), | ||
timeRangeStart: z | ||
.string() | ||
.datetime() | ||
.transform(getTimestampNsFromISO) | ||
.optional(), | ||
timeRangeEnd: z | ||
.string() | ||
.datetime() | ||
.transform(getTimestampNsFromISO) | ||
.optional(), | ||
sortColumn: z.string().optional(), | ||
sortOrder: z.enum(SORT_ORDERS, { message: 'Invalid sort order' }).optional(), | ||
nextPage: z.string().optional(), | ||
}); | ||
const listWorkflowsQueryParamSchema = z | ||
.object({ | ||
pageSize: z | ||
.string() | ||
.transform((val) => parseInt(val, 10)) | ||
.pipe( | ||
z.number().positive({ message: 'Page size must be a positive integer' }) | ||
), | ||
listType: z.enum(['default', 'archived']), | ||
inputType: z.enum(['search', 'query']), | ||
search: z.string().optional(), | ||
query: z.string().optional(), | ||
status: z | ||
.custom<WorkflowStatus>(isWorkflowStatus, { | ||
message: 'Invalid workflow status', | ||
}) | ||
.optional(), | ||
timeColumn: z | ||
.enum(['StartTime', 'CloseTime']) | ||
.optional() | ||
.default('StartTime'), | ||
timeRangeStart: z.string().datetime().optional(), | ||
timeRangeEnd: z.string().datetime().optional(), | ||
sortColumn: z.string().optional(), | ||
sortOrder: z | ||
.enum(SORT_ORDERS, { message: 'Invalid sort order' }) | ||
.optional(), | ||
nextPage: z.string().optional(), | ||
}) | ||
.superRefine((queryParams, ctx) => { | ||
if ( | ||
queryParams.listType === 'archived' && | ||
queryParams.inputType === 'search' | ||
) { | ||
if (queryParams.timeColumn === 'StartTime') { | ||
ctx.addIssue({ | ||
code: z.ZodIssueCode.custom, | ||
message: 'Cannot search for archived workflows by start time', | ||
}); | ||
} | ||
|
||
if (!queryParams.timeRangeStart || !queryParams.timeRangeEnd) { | ||
ctx.addIssue({ | ||
code: z.ZodIssueCode.custom, | ||
message: | ||
'Start and End time need to be passed for searching archived workflows', | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
export default listWorkflowsQueryParamSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters