Skip to content

Commit

Permalink
Update help API route that updates an existing Formio submission to l…
Browse files Browse the repository at this point in the history
…og when a helpdesk user performs that action
  • Loading branch information
courtneymyers committed Nov 27, 2024
1 parent 58e04b9 commit 7543353
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/server/app/routes/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
const { ensureAuthenticated, ensureHelpdesk } = require("../middleware");
const { getBapFormSubmissionData } = require("../utilities/bap");
const { getRebateIdFieldName } = require("../utilities/formio");
const log = require("../utilities/logger");

/**
* @typedef {'2022' | '2023' | '2024'} RebateYear
Expand Down Expand Up @@ -273,6 +274,7 @@ router.get("/formio/submission/:rebateYear/:formType/:id", async (req, res) => {
// --- post an update to an existing form submission to Formio (change submission to 'draft')
router.post("/formio/submission/:rebateYear/:formType/:mongoId", (req, res) => {
const { body } = req;
const { mail } = req.user;
const { rebateYear, formType, mongoId } = req.params;

// NOTE: included to support EPA API scan
Expand All @@ -292,14 +294,22 @@ router.post("/formio/submission/:rebateYear/:formType/:mongoId", (req, res) => {

if (!formioFormUrl) {
const errorStatus = 400;
const errorMessage = `Formio form URL does not exist for ${rebateYear} ${formName}.`;
const errorMessage = `Formio form URL does not exist for ${rebateYear} ${formName} form.`;
return res.status(errorStatus).json({ message: errorMessage });
}

axiosFormio(req)
.put(`${formioFormUrl}/submission/${mongoId}`, body)
.then((axiosRes) => axiosRes.data)
.then((submission) => res.json(submission))
.then((submission) => {
const logMessage =
`Helpdesk: User with email '${mail}' updated ${rebateYear} ` +
`${formType.toUpperCase()} submission '${mongoId}' ` +
`(status: '${submission.state}').`;
log({ level: "info", message: logMessage, req });

return res.json(submission);
})
.catch((error) => {
// NOTE: error is logged in axiosFormio response interceptor
const errorStatus = error.response?.status || 500;
Expand Down

0 comments on commit 7543353

Please sign in to comment.