In scope: - Consolidate `WorkflowService.getMany()`. - Support non-entity field `ownedBy` for `select`. - Support `tags` for `filter`. - Move `addOwnerId` to `OwnershipService`. - Remove unneeded check for `filter.id`. - Simplify DTO validation for `filter` and `select`. - Expand tests for `GET /workflows`. Workflow list query DTOs: ``` filter → name, active, tags select → id, name, active, tags, createdAt, updatedAt, versionId, ownedBy ``` Out of scope: - Migrate `shared_workflow.roleId` and `shared_credential.roleId` to string IDs. - Refactor `WorkflowHelpers.getSharedWorkflowIds()`.
35 lines
865 B
TypeScript
35 lines
865 B
TypeScript
/* eslint-disable @typescript-eslint/naming-convention */
|
|
|
|
import { WorkflowSelect } from './dtos/workflow.select.dto';
|
|
import * as ResponseHelper from '@/ResponseHelper';
|
|
import { toError } from '@/utils';
|
|
|
|
import type { RequestHandler } from 'express';
|
|
import type { ListQuery } from '@/requests';
|
|
|
|
export const selectListQueryMiddleware: RequestHandler = (req: ListQuery.Request, res, next) => {
|
|
const { select: rawSelect } = req.query;
|
|
|
|
if (!rawSelect) return next();
|
|
|
|
let Select;
|
|
|
|
if (req.baseUrl.endsWith('workflows')) {
|
|
Select = WorkflowSelect;
|
|
} else {
|
|
return next();
|
|
}
|
|
|
|
try {
|
|
const select = Select.fromString(rawSelect);
|
|
|
|
if (Object.keys(select).length === 0) return next();
|
|
|
|
req.listQueryOptions = { ...req.listQueryOptions, select };
|
|
|
|
next();
|
|
} catch (maybeError) {
|
|
ResponseHelper.sendErrorResponse(res, toError(maybeError));
|
|
}
|
|
};
|