From bd1b81eefc5a79826edd8b3260dc9ff01876b822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 15 Apr 2021 13:56:20 +0200 Subject: [PATCH] :hammer: Move tags validation to top --- packages/cli/src/Server.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 071e04d38f..f8bedc23f0 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -598,6 +598,14 @@ class App { // Updates an existing workflow this.app.patch(`/${this.restEndpoint}/workflows/:id`, ResponseHelper.send(async (req: IWorkflowRequest, res: express.Response): Promise => { const { tags } = req.body; + + const tagIds = tags; + + if (tagIds) { + await TagHelpers.validateTags(tagIds); + await TagHelpers.validateNotRelated(req.params.id, tagIds); + } + const newWorkflowData = _.omit(req.body, ['tags']) as IWorkflowBase; const id = req.params.id; @@ -667,15 +675,9 @@ class App { } } - const workflowId = id; - const tagIds = tags; - if (tagIds) { - await TagHelpers.validateTags(tagIds); - await TagHelpers.validateNotRelated(workflowId, tagIds); - - await TagHelpers.removeRelations(workflowId); - await TagHelpers.createRelations(workflowId, tagIds); + await TagHelpers.removeRelations(req.params.id); + await TagHelpers.createRelations(req.params.id, tagIds); const found = await Db.collections.Tag!.find({ select: ['id', 'name'],