Skip to content

Commit

Permalink
refactor: FORMS-1237 alphabetize functions (bcgov#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterMoar committed Aug 1, 2024
1 parent 81363aa commit 9e08f10
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions app/src/forms/common/middleware/validateParameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
};

0 comments on commit 9e08f10

Please sign in to comment.