async function listWorkflows()

in server/router/helpers/list-workflows.js [28:79]


async function listWorkflows({ clusterService, state }, ctx) {
  const { params = {}, query = {} } = ctx;
  const startTime = moment(query.startTime || NaN);
  const endTime = moment(query.endTime || NaN);

  ctx.assert(startTime.isValid() && endTime.isValid(), 400);

  const cluster = await clusterService.getCluster(ctx);

  const advancedVisibility = isAdvancedVisibilityEnabled(cluster);

  if (state === 'all') {
    ctx.assert(
      advancedVisibility,
      'Advanced visibility is not supported for cluster. Try using workflows open or closed APIs.',
      400
    );
  }

  const earliestTime = momentToLong(startTime);
  const latestTime = momentToLong(endTime);
  const { nextPageToken, status, workflowId, workflowName } = query;

  const requestArgs = advancedVisibility
    ? {
        query: buildQueryString(startTime, endTime, {
          ...query,
          state,
        }),
      }
    : {
        StartTimeFilter: {
          earliestTime,
          latestTime,
        },
        ...(workflowName && { typeFilter: { name: workflowName } }),
        ...(workflowId && { executionFilter: { workflowId } }),
        ...(status && { statusFilter: status }),
        nextPageToken,
      };

  const requestApi = advancedVisibility ? 'listWorkflows' : state + 'Workflows';

  const workflowListResponse = await ctx.cadence[requestApi](requestArgs);

  workflowListResponse.executions = injectDomainIntoWorkflowList(
    params.domain,
    workflowListResponse
  );

  ctx.body = workflowListResponse;
}