@gov-cy/govcy-express-services 1.3.0-alpha.2 → 1.3.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gov-cy/govcy-express-services",
3
- "version": "1.3.0-alpha.2",
3
+ "version": "1.3.0-alpha.3",
4
4
  "description": "An Express-based system that dynamically renders services using @gov-cy/govcy-frontend-renderer and posts data to a submission API.",
5
5
  "author": "DMRID - DSF Team",
6
6
  "license": "MIT",
package/src/index.mjs CHANGED
@@ -29,6 +29,7 @@ import { govcyFileDeletePageHandler, govcyFileDeletePostHandler } from './middle
29
29
  import { govcyFileViewHandler } from './middleware/govcyFileViewHandler.mjs';
30
30
  import { govcyMultipleThingsAddHandler, govcyMultipleThingsEditHandler, govcyMultipleThingsAddPostHandler, govcyMultipleThingsEditPostHandler } from './middleware/govcyMultipleThingsItemPage.mjs';
31
31
  import { govcyMultipleThingsDeletePageHandler, govcyMultipleThingsDeletePostHandler } from './middleware/govcyMultipleThingsDeleteHandler.mjs';
32
+ import { govcyUpdateMyDetailsPostHandler } from './middleware/govcyUpdateMyDetails.mjs';
32
33
  import { isProdOrStaging, getEnvVariable, whatsIsMyEnvironment } from './utils/govcyEnvVariables.mjs';
33
34
  import { logger } from "./utils/govcyLogger.mjs";
34
35
 
@@ -230,7 +231,6 @@ export default function initializeGovCyExpressService() {
230
231
  // ✅ -- ROUTE: Add Success Page Route (BEFORE the dynamic route)
231
232
  app.get('/:siteId/success', serviceConfigDataMiddleware, requireAuth, naturalPersonPolicy, govcyServiceEligibilityHandler(), govcySuccessPageHandler(), renderGovcyPage());
232
233
 
233
-
234
234
  // 👀🗃️ -- ROUTE: View file (BEFORE the dynamic route)
235
235
  app.get('/:siteId/:pageUrl/view-file/:elementName', serviceConfigDataMiddleware, requireAuth, naturalPersonPolicy, govcyServiceEligibilityHandler(), govcyLoadSubmissionData(), govcyFileViewHandler());
236
236
 
@@ -298,6 +298,16 @@ export default function initializeGovCyExpressService() {
298
298
  govcyMultipleThingsDeletePostHandler()
299
299
  );
300
300
 
301
+ // ----- `updateMyDetails` handling
302
+
303
+ // 🔀➡️ -- ROUTE coming from incoming update my details /:siteId/:pageUrl/update-my-details-response
304
+ app.post('/:siteId/:pageUrl/update-my-details-response',
305
+ serviceConfigDataMiddleware,
306
+ requireAuth,
307
+ naturalPersonPolicy,
308
+ govcyServiceEligibilityHandler(true),
309
+ govcyUpdateMyDetailsPostHandler());
310
+ // ----- `updateMyDetails` handling
301
311
 
302
312
  // 📝 -- ROUTE: Dynamic route to render pages based on siteId and pageUrl, using govcyPageHandler middleware
303
313
  app.get('/:siteId/:pageUrl', serviceConfigDataMiddleware, requireAuth, naturalPersonPolicy, govcyServiceEligibilityHandler(true), govcyLoadSubmissionData(), govcyPageHandler(), renderGovcyPage());
@@ -48,7 +48,6 @@ export function govcyMultipleThingsHubHandler(req, res, next, page, serviceCopy)
48
48
  {
49
49
  name: "main",
50
50
  elements: [
51
- // TODO: Add form element here
52
51
  {
53
52
  element: "form",
54
53
  params: {
@@ -5,6 +5,7 @@ import * as dataLayer from "../utils/govcyDataLayer.mjs";
5
5
  import { logger } from "../utils/govcyLogger.mjs";
6
6
  import { evaluatePageConditions } from "../utils/govcyExpressions.mjs";
7
7
  import { govcyMultipleThingsHubHandler } from "./govcyMultipleThingsHubHandler.mjs";
8
+ import { govcyUpdateMyDetailsHandler } from "./govcyUpdateMyDetails.mjs";
8
9
  // import {flattenContext, evaluateExpressionWithFlattening, evaluatePageConditions } from "../utils/govcyExpressions.mjs";
9
10
 
10
11
  /**
@@ -12,7 +13,7 @@ import { govcyMultipleThingsHubHandler } from "./govcyMultipleThingsHubHandler.m
12
13
  * This middleware processes the page template, populates form data, and shows validation errors.
13
14
  */
14
15
  export function govcyPageHandler() {
15
- return (req, res, next) => {
16
+ return async (req, res, next) => {
16
17
  try {
17
18
  // Extract siteId and pageUrl from request
18
19
  let { siteId, pageUrl } = req.params;
@@ -30,9 +31,6 @@ export function govcyPageHandler() {
30
31
  // 🔍 Find the page by pageUrl
31
32
  const page = getPageConfigData(serviceCopy, pageUrl);
32
33
 
33
- // Deep copy pageTemplate to avoid modifying the original
34
- const pageTemplateCopy = JSON.parse(JSON.stringify(page.pageTemplate));
35
-
36
34
  // ----- Conditional logic comes here
37
35
  // Check if the page has conditions and apply logic
38
36
  const result = evaluatePageConditions(page, req.session, req.params.siteId, req);
@@ -40,11 +38,20 @@ export function govcyPageHandler() {
40
38
  return res.redirect(`/${req.params.siteId}/${result.redirect}`);
41
39
  }
42
40
 
41
+ // ----- `updateMyDetails` handling
42
+ if (page.updateMyDetails) {
43
+ return await govcyUpdateMyDetailsHandler(req, res, next, page, serviceCopy);
44
+ }
45
+ // ----- `updateMyDetails` handling
46
+
43
47
  // ----- MultipleThings hub handling
44
48
  if (page.multipleThings) {
45
49
  logger.debug(`Rendering multipleThings hub for pageUrl: ${pageUrl}`, req);
46
50
  return govcyMultipleThingsHubHandler(req, res, next, page, serviceCopy);
47
51
  }
52
+
53
+ // Deep copy pageTemplate to avoid modifying the original
54
+ const pageTemplateCopy = JSON.parse(JSON.stringify(page.pageTemplate));
48
55
 
49
56
  //⚙️ Process forms before rendering
50
57
  pageTemplateCopy.sections.forEach(section => {
@@ -8,6 +8,7 @@ import { getEnvVariable, getEnvVariableBool } from "../utils/govcyEnvVariables.m
8
8
  import { handleMiddlewareError } from "../utils/govcyUtils.mjs";
9
9
  import { sendEmail } from "../utils/govcyNotification.mjs"
10
10
  import { evaluatePageConditions } from "../utils/govcyExpressions.mjs";
11
+ import { createUmdManualPageTemplate } from "./govcyUpdateMyDetails.mjs"
11
12
  import { validateMultipleThings } from "../utils/govcyMultipleThingsValidation.mjs";
12
13
 
13
14
  /**
@@ -38,9 +39,29 @@ export function govcyReviewPostHandler() {
38
39
 
39
40
  // Find the form definition inside `pageTemplate.sections`
40
41
  let formElement = null;
41
- for (const section of page.pageTemplate.sections) {
42
- formElement = section.elements.find(el => el.element === "form");
43
- if (formElement) break;
42
+
43
+ // ----- `updateMyDetails` handling
44
+ if (page.updateMyDetails) {
45
+ logger.debug("Validating UpdateMyDetails page during review POST", { siteId, pageUrl });
46
+ // Build the manual UMD page template
47
+ const umdTemplate = createUmdManualPageTemplate(siteId, service.site.lang, page, req);
48
+
49
+ // Extract the form element
50
+ formElement = umdTemplate .sections
51
+ .flatMap(section => section.elements)
52
+ .find(el => el.element === "form");
53
+
54
+ if (!formElement) {
55
+ logger.error("🚨 UMD form element not found during review validation", { siteId, pageUrl });
56
+ return handleMiddlewareError("🚨 UMD form element not found during review validation", 500, next);
57
+ }
58
+ // ----- `updateMyDetails` handling
59
+ } else {
60
+ // Normal flow
61
+ for (const section of page.pageTemplate.sections) {
62
+ formElement = section.elements.find(el => el.element === "form");
63
+ if (formElement) break;
64
+ }
44
65
  }
45
66
 
46
67
  if (!formElement) continue; // Skip pages without forms