From 6bb9d68da220848fde7cd453130677b1ef99fcea Mon Sep 17 00:00:00 2001 From: Jamie Howard Date: Wed, 23 Aug 2023 11:52:14 +0100 Subject: [PATCH] chore(ee): clean up controller --- .../controllers/workflows/stages/index.js | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/core/admin/ee/server/controllers/workflows/stages/index.js b/packages/core/admin/ee/server/controllers/workflows/stages/index.js index 06bf848c10..bdb678cc09 100644 --- a/packages/core/admin/ee/server/controllers/workflows/stages/index.js +++ b/packages/core/admin/ee/server/controllers/workflows/stages/index.js @@ -149,30 +149,31 @@ module.exports = { const entityStageId = entity[ENTITY_STAGE_ATTRIBUTE]?.id; const canTransition = stagePermissions.can(STAGE_TRANSITION_UID, entityStageId); - const workflowCount = await workflowService.count(); + const [workflowCount, { stages: workflowStages }] = await Promise.all([ + workflowService.count(), + workflowService.getAssignedWorkflow(modelUID, { + populate: 'stages', + }), + ]); + + const meta = { + stageCount: workflowStages.length, + workflowCount, + }; + if (!canTransition) { ctx.body = { data: [], - meta: { - stageCount: 0, - workflowCount, - }, + meta, }; return; } - const { stages: workflowStages } = await workflowService.getAssignedWorkflow(modelUID, { - populate: 'stages', - }); - const data = workflowStages.filter((stage) => stage.id !== entityStageId); ctx.body = { data, - meta: { - stageCount: data.length, - workflowCount, - }, + meta, }; }, };