From 53b0da25987fffc72c28ae1d66ebe8ba8652d3c5 Mon Sep 17 00:00:00 2001 From: Sanjay Babu Date: Sat, 8 Jun 2024 08:08:49 -0700 Subject: [PATCH] Send email confirmation when SHAS/Enquiry confirmation page is displayed --- .github/environments/values.dev.yaml | 1 + .github/environments/values.prod.yaml | 1 + .github/environments/values.test.yaml | 1 + app/config/custom-environment-variables.json | 3 ++- app/src/controllers/submission.ts | 17 +++++++++--- app/src/routes/v1/submission.ts | 9 +++++++ app/src/validators/submission.ts | 16 +++++++++++- charts/pcns/values.yaml | 1 + .../housing/intake/ShasEnquiryForm.vue | 26 +++++++++++++++++++ .../housing/intake/ShasIntakeForm.vue | 24 ++++++++++++++++- frontend/src/services/submissionService.ts | 18 +++++++++++++ frontend/src/utils/templates.ts | 10 +++++++ 12 files changed, 121 insertions(+), 6 deletions(-) diff --git a/.github/environments/values.dev.yaml b/.github/environments/values.dev.yaml index 5a4ece75e..a5e1c6b1e 100644 --- a/.github/environments/values.dev.yaml +++ b/.github/environments/values.dev.yaml @@ -4,6 +4,7 @@ config: configMap: FRONTEND_APIPATH: api/v1 FRONTEND_CHES_BCC: NRM.PermittingAndData@gov.bc.ca + FRONTEND_CHES_CC: NRM.PermittingAndData@gov.bc.ca FRONTEND_COMS_APIPATH: https://coms-dev.api.gov.bc.ca/api/v1 FRONTEND_COMS_BUCKETID: 1f9e1451-c130-4804-aeb0-b78b5b109c47 FRONTEND_GEOCODER_APIPATH: https://geocoder.api.gov.bc.ca diff --git a/.github/environments/values.prod.yaml b/.github/environments/values.prod.yaml index 9a23a0043..1a5ae0282 100644 --- a/.github/environments/values.prod.yaml +++ b/.github/environments/values.prod.yaml @@ -4,6 +4,7 @@ config: configMap: FRONTEND_APIPATH: api/v1 FRONTEND_CHES_BCC: Housing.Authorizations@gov.bc.ca + FRONTEND_CHES_CC: Housing.Authorizations@gov.bc.ca FRONTEND_COMS_APIPATH: https://coms.api.gov.bc.ca/api/v1 FRONTEND_COMS_BUCKETID: 0089d041-5aab-485e-842d-8875475d0ed6 FRONTEND_GEOCODER_APIPATH: https://geocoder.api.gov.bc.ca diff --git a/.github/environments/values.test.yaml b/.github/environments/values.test.yaml index 5a098323a..4434915b0 100644 --- a/.github/environments/values.test.yaml +++ b/.github/environments/values.test.yaml @@ -4,6 +4,7 @@ config: configMap: FRONTEND_APIPATH: api/v1 FRONTEND_CHES_BCC: NRM.PermittingAndData@gov.bc.ca + FRONTEND_CHES_CC: NRM.PermittingAndData@gov.bc.ca FRONTEND_COMS_APIPATH: https://coms-test.api.gov.bc.ca/api/v1 FRONTEND_COMS_BUCKETID: a9eabd1d-5f77-4c60-bf6b-83ffa0e21c59 FRONTEND_GEOCODER_APIPATH: https://geocoder.api.gov.bc.ca diff --git a/app/config/custom-environment-variables.json b/app/config/custom-environment-variables.json index 121950574..57d799adf 100644 --- a/app/config/custom-environment-variables.json +++ b/app/config/custom-environment-variables.json @@ -2,7 +2,8 @@ "frontend": { "apiPath": "FRONTEND_APIPATH", "ches": { - "bcc": "FRONTEND_CHES_BCC" + "bcc": "FRONTEND_CHES_BCC", + "cc": "FRONTEND_CHES_CC" }, "coms": { "apiPath": "FRONTEND_COMS_APIPATH", diff --git a/app/src/controllers/submission.ts b/app/src/controllers/submission.ts index e4e401d0e..535aa2258 100644 --- a/app/src/controllers/submission.ts +++ b/app/src/controllers/submission.ts @@ -11,10 +11,10 @@ import { YES_NO_UNSURE } from '../components/constants'; import { camelCaseToTitleCase, deDupeUnsure, getCurrentIdentity, isTruthy, toTitleCase } from '../components/utils'; -import { activityService, submissionService, permitService, userService } from '../services'; +import { activityService, emailService, submissionService, permitService, userService } from '../services'; import type { NextFunction, Request, Response } from '../interfaces/IExpress'; -import type { ChefsFormConfig, ChefsFormConfigData, Submission, ChefsSubmissionExport, Permit } from '../types'; +import type { ChefsFormConfig, ChefsFormConfigData, Email, Submission, ChefsSubmissionExport, Permit } from '../types'; const controller = { checkAndStoreNewSubmissions: async () => { @@ -299,7 +299,6 @@ const controller = { // Create each permit await Promise.all(appliedPermits.map(async (x: Permit) => await permitService.createPermit(x))); await Promise.all(investigatePermits.map(async (x: Permit) => await permitService.createPermit(x))); - res.status(201).json({ activityId: result.activityId, submissionId: result.submissionId }); } catch (e: unknown) { next(e); @@ -410,6 +409,18 @@ const controller = { } catch (e: unknown) { next(e); } + }, + /** + * @function emailConfirmation + * Send an email with the confirmation of submission + */ + emailConfirmation: async (req: Request, res: Response, next: NextFunction) => { + try { + const { data, status } = await emailService.email(req.body.emailData); + res.status(status).json(data); + } catch (e: unknown) { + next(e); + } } }; diff --git a/app/src/routes/v1/submission.ts b/app/src/routes/v1/submission.ts index 786b192b4..dd2b166e3 100644 --- a/app/src/routes/v1/submission.ts +++ b/app/src/routes/v1/submission.ts @@ -32,6 +32,15 @@ router.put('/draft/:submissionId', (req: Request, res: Response, next: NextFunct submissionController.updateDraft(req, res, next); }); +// Send an email with the confirmation of submission +router.put( + '/emailConfirmation', + submissionValidator.emailConfirmation, + (req: Request, res: Response, next: NextFunction): void => { + submissionController.emailConfirmation(req, res, next); + } +); + /** Creates a submission */ router.put('/', submissionValidator.createSubmission, (req: Request, res: Response, next: NextFunction): void => { submissionController.createSubmission(req, res, next); diff --git a/app/src/validators/submission.ts b/app/src/validators/submission.ts index 4fd596d9a..8ccffd12f 100644 --- a/app/src/validators/submission.ts +++ b/app/src/validators/submission.ts @@ -95,6 +95,19 @@ const schema = { params: Joi.object({ submissionId: uuidv4.required() }) + }, + emailConfirmation: { + body: Joi.object({ + emailData: Joi.object().keys({ + bcc: Joi.array().items(emailJoi).allow(null), + bodyType: Joi.string().required().allow(null), + body: Joi.string().required(), + cc: Joi.array().items(emailJoi), + from: emailJoi.required(), + subject: Joi.string().required(), + to: Joi.array().items(emailJoi).required() + }) + }) } }; @@ -104,5 +117,6 @@ export default { deleteSubmission: validate(schema.deleteSubmission), getStatistics: validate(schema.getStatistics), getSubmission: validate(schema.getSubmission), - updateSubmission: validate(schema.updateSubmission) + updateSubmission: validate(schema.updateSubmission), + emailConfirmation: validate(schema.emailConfirmation) }; diff --git a/charts/pcns/values.yaml b/charts/pcns/values.yaml index fe867bc03..9be4c7e84 100644 --- a/charts/pcns/values.yaml +++ b/charts/pcns/values.yaml @@ -133,6 +133,7 @@ config: configMap: FRONTEND_APIPATH: api/v1 FRONTEND_CHES_BCC: ~ + FRONTEND_CHES_CC: ~ FRONTEND_COMS_APIPATH: ~ FRONTEND_COMS_BUCKETID: ~ FRONTEND_GEOCODER_APIPATH: ~ diff --git a/frontend/src/components/housing/intake/ShasEnquiryForm.vue b/frontend/src/components/housing/intake/ShasEnquiryForm.vue index 22b096614..71b31f9a2 100644 --- a/frontend/src/components/housing/intake/ShasEnquiryForm.vue +++ b/frontend/src/components/housing/intake/ShasEnquiryForm.vue @@ -1,4 +1,5 @@