mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 03:12:15 +00:00
refactor: Consolidate WorkflowService.getMany() (no-changelog) (#6892)
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()`.
This commit is contained in:
@@ -1,27 +1,25 @@
|
||||
import type { ListQueryRequest } from '@/requests';
|
||||
import { isIntegerString } from '@/utils';
|
||||
import { toError } from '@/utils';
|
||||
import * as ResponseHelper from '@/ResponseHelper';
|
||||
import { Pagination } from './dtos/pagination.dto';
|
||||
import type { ListQuery } from '@/requests';
|
||||
import type { RequestHandler } from 'express';
|
||||
|
||||
function toPaginationOptions(rawTake: string, rawSkip: string) {
|
||||
const MAX_ITEMS = 50;
|
||||
|
||||
if ([rawTake, rawSkip].some((i) => !isIntegerString(i))) {
|
||||
throw new Error('Parameter take or skip is not an integer string');
|
||||
}
|
||||
|
||||
const [take, skip] = [rawTake, rawSkip].map((o) => parseInt(o, 10));
|
||||
|
||||
return { skip, take: Math.min(take, MAX_ITEMS) };
|
||||
}
|
||||
|
||||
export const paginationListQueryMiddleware: RequestHandler = (req: ListQueryRequest, res, next) => {
|
||||
export const paginationListQueryMiddleware: RequestHandler = (
|
||||
req: ListQuery.Request,
|
||||
res,
|
||||
next,
|
||||
) => {
|
||||
const { take: rawTake, skip: rawSkip = '0' } = req.query;
|
||||
|
||||
if (!rawTake) return next();
|
||||
|
||||
const { take, skip } = toPaginationOptions(rawTake, rawSkip);
|
||||
try {
|
||||
const { take, skip } = Pagination.fromString(rawTake, rawSkip);
|
||||
|
||||
req.listQueryOptions = { ...req.listQueryOptions, take, skip };
|
||||
req.listQueryOptions = { ...req.listQueryOptions, skip, take };
|
||||
|
||||
next();
|
||||
next();
|
||||
} catch (maybeError) {
|
||||
ResponseHelper.sendErrorResponse(res, toError(maybeError));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user