@gov-cy/govcy-express-services 1.3.0-alpha.3 → 1.3.0-alpha.5
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.
|
|
3
|
+
"version": "1.3.0-alpha.5",
|
|
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",
|
|
@@ -23,11 +23,19 @@ export function govcyReviewPostHandler() {
|
|
|
23
23
|
// ✅ Load service and check if it exists
|
|
24
24
|
const service = req.serviceData;
|
|
25
25
|
let validationErrors = {};
|
|
26
|
-
|
|
26
|
+
// to be used for sending email
|
|
27
|
+
let updateMyDetailsData = null;
|
|
28
|
+
|
|
27
29
|
// Loop through all pages in the service
|
|
28
30
|
for (const page of service.pages) {
|
|
29
31
|
//get page url
|
|
30
32
|
const pageUrl = page.pageData.url;
|
|
33
|
+
|
|
34
|
+
// to be used for sending email
|
|
35
|
+
// get updateMyDetails data if not found before
|
|
36
|
+
if (!updateMyDetailsData) {
|
|
37
|
+
updateMyDetailsData = dataLayer.getPageUpdateMyDetails(req.session, siteId, pageUrl);
|
|
38
|
+
}
|
|
31
39
|
|
|
32
40
|
// ----- Conditional logic comes here
|
|
33
41
|
// ✅ Skip validation if page is conditionally excluded
|
|
@@ -165,9 +173,22 @@ export function govcyReviewPostHandler() {
|
|
|
165
173
|
// Generate the email body
|
|
166
174
|
let emailBody = generateSubmitEmail(service, submissionData.printFriendlyData, referenceNo, req);
|
|
167
175
|
logger.debug("Email generated:", emailBody);
|
|
176
|
+
|
|
177
|
+
let emailAddress = "";
|
|
178
|
+
// if Update my details not provided the use user email
|
|
179
|
+
if (!updateMyDetailsData || !updateMyDetailsData.email) {
|
|
180
|
+
emailAddress = dataLayer.getUser(req.session).email;
|
|
181
|
+
} else {
|
|
182
|
+
emailAddress = updateMyDetailsData.email;
|
|
183
|
+
}
|
|
184
|
+
|
|
168
185
|
// Send the email
|
|
169
|
-
sendEmail(
|
|
170
|
-
|
|
186
|
+
sendEmail(
|
|
187
|
+
service.site.title[service.site.lang],
|
|
188
|
+
emailBody,
|
|
189
|
+
[emailAddress],
|
|
190
|
+
"eMail").catch(err => {
|
|
191
|
+
logger.error("Email sending failed (async):", err);
|
|
171
192
|
});
|
|
172
193
|
// --- End of email sending
|
|
173
194
|
|
|
@@ -162,6 +162,9 @@ export async function govcyUpdateMyDetailsHandler(req, res, next, page, serviceC
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
// Deep copy pageTemplate to avoid modifying the original
|
|
166
|
+
const pageTemplateCopy = JSON.parse(JSON.stringify(pageTemplate));
|
|
167
|
+
|
|
165
168
|
// if the page variant is 1 or 2 which means it has a form
|
|
166
169
|
if (pageVariant === 1 || pageVariant === 2) {
|
|
167
170
|
// Handle form data
|
|
@@ -181,7 +184,7 @@ export async function govcyUpdateMyDetailsHandler(req, res, next, page, serviceC
|
|
|
181
184
|
|
|
182
185
|
|
|
183
186
|
populateFormData(
|
|
184
|
-
|
|
187
|
+
pageTemplateCopy.sections[0].elements[0].params.elements,
|
|
185
188
|
theData,
|
|
186
189
|
validationErrors,
|
|
187
190
|
req.session,
|
|
@@ -194,18 +197,18 @@ export async function govcyUpdateMyDetailsHandler(req, res, next, page, serviceC
|
|
|
194
197
|
|
|
195
198
|
// if there are validation errors, add an error summary
|
|
196
199
|
if (validationErrors?.errorSummary?.length > 0) {
|
|
197
|
-
|
|
200
|
+
pageTemplateCopy.sections[0].elements[0].params.elements.unshift(govcyResources.errorSummary(validationErrors.errorSummary));
|
|
198
201
|
}
|
|
199
202
|
}
|
|
200
203
|
|
|
201
204
|
// Add topElements if provided
|
|
202
205
|
if (Array.isArray(umdConfig.topElements)) {
|
|
203
|
-
|
|
206
|
+
pageTemplateCopy.sections[0].elements[0].params.elements.unshift(...umdConfig.topElements);
|
|
204
207
|
}
|
|
205
208
|
|
|
206
209
|
//if hasBackLink == true add section beforeMain with backlink element
|
|
207
210
|
if (umdConfig?.hasBackLink == true) {
|
|
208
|
-
|
|
211
|
+
pageTemplateCopy.sections.unshift({
|
|
209
212
|
name: "beforeMain",
|
|
210
213
|
elements: [
|
|
211
214
|
{
|
|
@@ -226,7 +229,7 @@ export async function govcyUpdateMyDetailsHandler(req, res, next, page, serviceC
|
|
|
226
229
|
mainLayout: page?.pageData?.mainLayout || "two-third"
|
|
227
230
|
}
|
|
228
231
|
},
|
|
229
|
-
pageTemplate:
|
|
232
|
+
pageTemplate: pageTemplateCopy
|
|
230
233
|
};
|
|
231
234
|
|
|
232
235
|
logger.debug("Processed `govcyUpdateMyDetailsHandler` page data:", req.processedPage, req);
|
|
@@ -442,12 +445,14 @@ export function govcyUpdateMyDetailsPostHandler() {
|
|
|
442
445
|
// --------------- Page variant 1:Manual form for non-eligible users
|
|
443
446
|
//⤴️ Store validated form data in session
|
|
444
447
|
dataLayer.storePageData(req.session, siteId, pageUrl, formData);
|
|
448
|
+
dataLayer.storePageUpdateMyDetails(req.session, siteId, pageUrl, formData);
|
|
445
449
|
} else if (pageVariant === 2) {
|
|
446
450
|
// --------------- Page variant 2: Confirmation radio for eligible users with data
|
|
447
451
|
const userChoice = req.body?.useTheseDetails?.trim().toLowerCase();
|
|
448
452
|
if (userChoice === "yes") {
|
|
449
453
|
//⤴️ Store validated form data in session
|
|
450
454
|
dataLayer.storePageData(req.session, siteId, pageUrl, userDetails);
|
|
455
|
+
dataLayer.storePageUpdateMyDetails(req.session, siteId, pageUrl, userDetails);
|
|
451
456
|
} else if (userChoice === "no") {
|
|
452
457
|
// construct the return url to go to `:siteId/:pageUrl` + `?route=` + `review`
|
|
453
458
|
const returnUrl = `${req.protocol}://${req.get("host")}${govcyResources.constructPageUrl(siteId, page.pageData.url, (req.query.route === "review" ? "review" : ""))}`;
|
|
@@ -248,6 +248,34 @@ export function getSiteEligibilityResult(store, siteId, endpointKey, maxAgeMs =
|
|
|
248
248
|
return entry.result;
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Stores the update my details data for contact purposes, outside the scope of formData
|
|
253
|
+
*
|
|
254
|
+
* For example `store.siteData[siteId].inputData[pageUrl]["updateMyDetails"] = value`
|
|
255
|
+
*
|
|
256
|
+
* @param {object} store The session store
|
|
257
|
+
* @param {string} siteId The site id
|
|
258
|
+
* @param {string} pageUrl The page url
|
|
259
|
+
* @param {object} userData The user's update my details data
|
|
260
|
+
*/
|
|
261
|
+
export function storePageUpdateMyDetails(store, siteId, pageUrl, userData) {
|
|
262
|
+
// Ensure session structure is initialized
|
|
263
|
+
initializeSiteData(store, siteId, pageUrl);
|
|
264
|
+
|
|
265
|
+
store.siteData[siteId].inputData[pageUrl]["updateMyDetails"] = userData;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Get the update my details data for contact purposes, outside the scope of formData
|
|
270
|
+
* @param {object} store The session store
|
|
271
|
+
* @param {string} siteId The site id
|
|
272
|
+
* @param {string} pageUrl The page url
|
|
273
|
+
* @returns The user's update my details data
|
|
274
|
+
*/
|
|
275
|
+
export function getPageUpdateMyDetails(store, siteId, pageUrl) {
|
|
276
|
+
return store?.siteData?.[siteId]?.inputData?.[pageUrl]?.["updateMyDetails"] || null;
|
|
277
|
+
}
|
|
278
|
+
|
|
251
279
|
/**
|
|
252
280
|
* Get the page validation errors from the store and clear them
|
|
253
281
|
*
|