@gov-cy/govcy-express-services 1.3.0-alpha.6 → 1.3.0
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 +1 -1
- package/src/middleware/govcyFileDeleteHandler.mjs +3 -1
- package/src/middleware/govcyHttpErrorHandler.mjs +5 -0
- package/src/middleware/govcyReviewPostHandler.mjs +13 -10
- package/src/middleware/govcyServiceEligibilityHandler.mjs +15 -12
- package/src/middleware/govcySuccessPageHandler.mjs +10 -1
- package/src/resources/govcyResources.mjs +9 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gov-cy/govcy-express-services",
|
|
3
|
-
"version": "1.3.0
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|
|
@@ -53,7 +53,9 @@ export function govcyFileDeletePageHandler() {
|
|
|
53
53
|
|
|
54
54
|
// Guard if still nothing found
|
|
55
55
|
if (!elementData || !elementData.fileId || !elementData.sha256) {
|
|
56
|
-
|
|
56
|
+
logger.info(`govcyFileDeletePageHandler: File data not found for element [${elementName}] on page [${pageUrl}] in site [${siteId}]. Redirecting to "${siteId}/${pageUrl}".`);
|
|
57
|
+
return res.redirect(govcyResources.constructPageUrl(siteId, pageUrl, (req.query.route === "review" ? "review" : "")))
|
|
58
|
+
// return handleMiddlewareError(`File input [${elementName}] data not found on this page`, 404, next);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
|
|
@@ -52,6 +52,11 @@ export function govcyHttpErrorHandler(err, req, res, next) {
|
|
|
52
52
|
res.status(statusCode);
|
|
53
53
|
|
|
54
54
|
if (isApiRequest(req)) {
|
|
55
|
+
if (err.code === `LIMIT_FILE_SIZE` && err.name === `MulterError`) {
|
|
56
|
+
statusCode = 409;
|
|
57
|
+
message = "File exceeds allowed size";
|
|
58
|
+
return res.status(400).json(errorResponse(statusCode, message));
|
|
59
|
+
}
|
|
55
60
|
return res.status(statusCode).json(errorResponse(statusCode, message));
|
|
56
61
|
}
|
|
57
62
|
|
|
@@ -163,6 +163,18 @@ export function govcyReviewPostHandler() {
|
|
|
163
163
|
// Add the reference number to the submission data
|
|
164
164
|
submissionData.referenceNumber = referenceNo;
|
|
165
165
|
logger.info("✅ Data submitted", siteId, referenceNo);
|
|
166
|
+
|
|
167
|
+
// Get the user email address
|
|
168
|
+
let emailAddress = "";
|
|
169
|
+
// if Update my details not provided the use user email
|
|
170
|
+
if (!updateMyDetailsData || !updateMyDetailsData.email) {
|
|
171
|
+
emailAddress = dataLayer.getUser(req.session).email;
|
|
172
|
+
} else {
|
|
173
|
+
emailAddress = updateMyDetailsData.email;
|
|
174
|
+
}
|
|
175
|
+
// add contact email to submission data
|
|
176
|
+
submissionData.contactEmailAddress = emailAddress;
|
|
177
|
+
|
|
166
178
|
// handle data layer submission
|
|
167
179
|
dataLayer.storeSiteSubmissionData(
|
|
168
180
|
req.session,
|
|
@@ -172,16 +184,7 @@ export function govcyReviewPostHandler() {
|
|
|
172
184
|
//-- Send email to user
|
|
173
185
|
// Generate the email body
|
|
174
186
|
let emailBody = generateSubmitEmail(service, submissionData.printFriendlyData, referenceNo, req);
|
|
175
|
-
|
|
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
|
-
|
|
187
|
+
|
|
185
188
|
// Send the email
|
|
186
189
|
sendEmail(
|
|
187
190
|
service.site.title[service.site.lang],
|
|
@@ -26,19 +26,22 @@ export function govcyServiceEligibilityHandler(checkForForm = false) {
|
|
|
26
26
|
if (!pageUrl) pageUrl = "index";
|
|
27
27
|
// 🔍 Find the page by pageUrl
|
|
28
28
|
const page = getPageConfigData(service, pageUrl);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
section
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
// ----- `updateMyDetails` handling. always run eligibility for updateMyDetails
|
|
30
|
+
if (!page.updateMyDetails) {
|
|
31
|
+
if (!page || !page.pageTemplate) return next(); // Defensive: skip if no template
|
|
32
|
+
// Deep copy pageTemplate to avoid modifying the original
|
|
33
|
+
const pageTemplateCopy = JSON.parse(JSON.stringify(page.pageTemplate));
|
|
34
|
+
|
|
35
|
+
// Check if any section contains a form element
|
|
36
|
+
const hasForm = pageTemplateCopy.sections?.some(section =>
|
|
37
|
+
section.elements?.some(el => el.element === "form")
|
|
38
|
+
);
|
|
39
|
+
if (!hasForm) {
|
|
40
|
+
// No form found, skip eligibility check
|
|
41
|
+
return next();
|
|
42
|
+
}
|
|
43
|
+
// else: continue with eligibility check
|
|
40
44
|
}
|
|
41
|
-
// else: continue with eligibility check
|
|
42
45
|
}
|
|
43
46
|
const eligibilityEndpoints = service?.site?.eligibilityAPIEndpoints || [];
|
|
44
47
|
const user = dataLayer.getUser(req.session); // Get the user from the session;
|
|
@@ -44,12 +44,21 @@ export function govcySuccessPageHandler(isPDF = false) {
|
|
|
44
44
|
// }
|
|
45
45
|
]
|
|
46
46
|
};
|
|
47
|
+
|
|
48
|
+
let weHaveSendYouAnEmailText = JSON.parse(JSON.stringify(govcyResources.staticResources.text.weHaveSendYouAnEmail));
|
|
49
|
+
// Replace label placeholders for email
|
|
50
|
+
for (const lang of Object.keys(weHaveSendYouAnEmailText)) {
|
|
51
|
+
weHaveSendYouAnEmailText[lang] = weHaveSendYouAnEmailText[lang].replace("{{email}}",
|
|
52
|
+
submissionData.contactEmailAddress || ""
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
// Construct page title
|
|
48
57
|
const weHaveSendYouAnEmail = {
|
|
49
58
|
element: "textElement",
|
|
50
59
|
params: {
|
|
51
60
|
type: "p",
|
|
52
|
-
text:
|
|
61
|
+
text: weHaveSendYouAnEmailText
|
|
53
62
|
}
|
|
54
63
|
};
|
|
55
64
|
|
|
@@ -102,9 +102,9 @@ export const staticResources = {
|
|
|
102
102
|
tr: "Your reference number: "
|
|
103
103
|
},
|
|
104
104
|
weHaveSendYouAnEmail: {
|
|
105
|
-
en: "We have sent you a confirmation email.",
|
|
106
|
-
el: "Έχουμε στείλει email
|
|
107
|
-
tr: "We have sent you a confirmation email."
|
|
105
|
+
en: "We have sent you a confirmation email at \"{{email}}\".",
|
|
106
|
+
el: "Έχουμε στείλει email επιβεβαιωσης στο \"{{email}}\".",
|
|
107
|
+
tr: "We have sent you a confirmation email at \"{{email}}\"."
|
|
108
108
|
},
|
|
109
109
|
theDataFromYourRequest: {
|
|
110
110
|
en: "The data from your request: ",
|
|
@@ -182,14 +182,14 @@ export const staticResources = {
|
|
|
182
182
|
tr: "This entry already exists"
|
|
183
183
|
},
|
|
184
184
|
multipleThingsMaxMessage: {
|
|
185
|
-
en: "You have reached the maximum number of entries. You can only add up to {{max}}
|
|
186
|
-
el: "Έχετε φτάσει το μέγιστο αριθμό καταχωρίσεων. Μπορείτε να προσθέσετε μόνο έως {{max}}
|
|
187
|
-
tr: "You have reached the maximum number of entries. You can only add up to {{max}}
|
|
185
|
+
en: "You have reached the maximum number of entries. You can only add up to {{max}}",
|
|
186
|
+
el: "Έχετε φτάσει το μέγιστο αριθμό καταχωρίσεων. Μπορείτε να προσθέσετε μόνο έως {{max}}",
|
|
187
|
+
tr: "You have reached the maximum number of entries. You can only add up to {{max}}"
|
|
188
188
|
},
|
|
189
189
|
multipleThingsMinMessage: {
|
|
190
|
-
en: "You have not added the minimum number of entries. You must add at least {{min}}
|
|
191
|
-
el: "Δεν έχετε προσθέσει τον ελάχιστο αριθμό καταχωρίσεων. Πρέπει να προσθέσετε τουλάχιστον {{min}}
|
|
192
|
-
tr: "You have not added the minimum number of entries. You must add at least {{min}}
|
|
190
|
+
en: "You have not added the minimum number of entries. You must add at least {{min}}",
|
|
191
|
+
el: "Δεν έχετε προσθέσει τον ελάχιστο αριθμό καταχωρίσεων. Πρέπει να προσθέσετε τουλάχιστον {{min}}",
|
|
192
|
+
tr: "You have not added the minimum number of entries. You must add at least {{min}}"
|
|
193
193
|
},
|
|
194
194
|
multipleThingsItemsValidationPrefix: {
|
|
195
195
|
en: "Entry {{index}} - ",
|