From 9e08f100954016fffc5d9df9023c51fe9375dc6d Mon Sep 17 00:00:00 2001 From: Walter Moar Date: Thu, 1 Aug 2024 08:55:37 -0700 Subject: [PATCH] refactor: FORMS-1237 alphabetize functions (#1456) --- .../common/middleware/validateParameter.js | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/app/src/forms/common/middleware/validateParameter.js b/app/src/forms/common/middleware/validateParameter.js index 8e8727a98..2132b2794 100644 --- a/app/src/forms/common/middleware/validateParameter.js +++ b/app/src/forms/common/middleware/validateParameter.js @@ -60,6 +60,32 @@ const validateDocumentTemplateId = async (req, _res, next, documentTemplateId) = } }; +/** + * Validates that the :externalApiId route parameter exists and is a UUID. This + * validator requires that the :formId route parameter also exists. + * + * @param {*} req the Express object representing the HTTP request. + * @param {*} _res the Express object representing the HTTP response - unused. + * @param {*} next the Express chaining function. + * @param {*} externalAPIId the :externalAPIId value from the route. + */ +const validateExternalAPIId = async (req, _res, next, externalAPIId) => { + try { + _validateUuid(externalAPIId, 'externalAPIId'); + + const externalApi = await externalApiService.readExternalAPI(externalAPIId); + if (!externalApi || externalApi.formId !== req.params.formId) { + throw new Problem(404, { + detail: 'externalAPIId does not exist on this form', + }); + } + + next(); + } catch (error) { + next(error); + } +}; + /** * Validates that the :fileId route parameter exists and is a UUID. * @@ -148,37 +174,11 @@ const validateFormVersionId = async (req, _res, next, formVersionId) => { } }; -/** - * Validates that the :externalApiId route parameter exists and is a UUID. This - * validator requires that the :formId route parameter also exists. - * - * @param {*} req the Express object representing the HTTP request. - * @param {*} _res the Express object representing the HTTP response - unused. - * @param {*} next the Express chaining function. - * @param {*} externalAPIId the :externalAPIId value from the route. - */ -const validateExternalAPIId = async (req, _res, next, externalAPIId) => { - try { - _validateUuid(externalAPIId, 'externalAPIId'); - - const externalApi = await externalApiService.readExternalAPI(externalAPIId); - if (!externalApi || externalApi.formId !== req.params.formId) { - throw new Problem(404, { - detail: 'externalAPIId does not exist on this form', - }); - } - - next(); - } catch (error) { - next(error); - } -}; - module.exports = { validateDocumentTemplateId, + validateExternalAPIId, validateFileId, validateFormId, - validateFormVersionId, validateFormVersionDraftId, - validateExternalAPIId, + validateFormVersionId, };