Skip to content

Commit

Permalink
refactor: tidy up submission_email references (#3633)
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Sep 6, 2024
1 parent 64e8304 commit eef7809
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 59 deletions.
4 changes: 2 additions & 2 deletions api.planx.uk/modules/send/downloadApplicationFiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export async function downloadApplicationFiles(

try {
// Confirm that the provided email matches the stored team settings for the provided localAuthority
const { notifyPersonalisation } = await getTeamEmailSettings(
const { teamSettings } = await getTeamEmailSettings(
req.query.localAuthority as string,
);
if (notifyPersonalisation.sendToEmail !== req.query.email) {
if (teamSettings.submissionEmail !== req.query.email) {
return next({
status: 403,
message:
Expand Down
12 changes: 6 additions & 6 deletions api.planx.uk/modules/send/email/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ describe(`sending an application by email to a planning office`, () => {
data: {
teams: [
{
notifyPersonalisation: {
teamSettings: {
emailReplyToId: "abc123",
sendToEmail: "[email protected]",
submissionEmail: "[email protected]",
},
},
],
Expand Down Expand Up @@ -154,9 +154,9 @@ describe(`sending an application by email to a planning office`, () => {
data: {
teams: [
{
notifyPersonalisation: {
teamSettings: {
emailReplyToId: "abc123",
sendToEmail: null,
submissionEmail: null,
},
},
],
Expand Down Expand Up @@ -206,8 +206,8 @@ describe(`downloading application data received by email`, () => {
data: {
teams: [
{
notifyPersonalisation: {
sendToEmail: "[email protected]",
teamSettings: {
submissionEmail: "[email protected]",
},
},
],
Expand Down
15 changes: 7 additions & 8 deletions api.planx.uk/modules/send/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export async function sendToEmail(

try {
// Confirm this local authority (aka team) has an email configured in teams.submission_email
const { notifyPersonalisation } =
await getTeamEmailSettings(localAuthority);
if (!notifyPersonalisation.sendToEmail) {
const { teamSettings } = await getTeamEmailSettings(localAuthority);
if (!teamSettings.submissionEmail) {
return next({
status: 400,
message: `Send to email is not enabled for this local authority (${localAuthority})`,
Expand All @@ -47,15 +46,15 @@ export async function sendToEmail(
serviceName: flowName,
sessionId: payload.sessionId,
applicantEmail: email,
downloadLink: `${process.env.API_URL_EXT}/download-application-files/${payload.sessionId}?email=${notifyPersonalisation.sendToEmail}&localAuthority=${localAuthority}`,
...notifyPersonalisation,
downloadLink: `${process.env.API_URL_EXT}/download-application-files/${payload.sessionId}?email=${teamSettings.submissionEmail}&localAuthority=${localAuthority}`,
...teamSettings,
},
};

// Send the email
const response = await sendEmail(
"submit",
notifyPersonalisation.sendToEmail,
teamSettings.submissionEmail,
config,
);

Expand All @@ -66,14 +65,14 @@ export async function sendToEmail(
insertAuditEntry(
payload.sessionId,
localAuthority,
notifyPersonalisation.sendToEmail,
teamSettings.submissionEmail,
config,
response,
);

return res.status(200).send({
message: `Successfully sent to email`,
inbox: notifyPersonalisation.sendToEmail,
inbox: teamSettings.submissionEmail,
govuk_notify_template: "Submit",
});
} catch (error) {
Expand Down
11 changes: 4 additions & 7 deletions api.planx.uk/modules/send/email/service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { gql } from "graphql-request";
import { $api } from "../../../client/index.js";
import {
NotifyPersonalisation,
Session,
} from "@opensystemslab/planx-core/types";
import { Session, TeamContactSettings } from "@opensystemslab/planx-core/types";
import { EmailSubmissionNotifyConfig } from "../../../types.js";

interface GetTeamEmailSettings {
teams: {
notifyPersonalisation: NotifyPersonalisation & { sendToEmail: string };
teamSettings: TeamContactSettings;
}[];
}

Expand All @@ -17,12 +14,12 @@ export async function getTeamEmailSettings(localAuthority: string) {
gql`
query GetTeamEmailSettings($slug: String) {
teams(where: { slug: { _eq: $slug } }) {
notifyPersonalisation: team_settings {
teamSettings: team_settings {
helpEmail: help_email
helpPhone: help_phone
emailReplyToId: email_reply_to_id
helpOpeningHours: help_opening_hours
sendToEmail: submission_email
submissionEmail: submission_email
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@airbrake/node": "^2.1.8",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#931d4db",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#ec52620",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand Down
14 changes: 7 additions & 7 deletions api.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/tests/api-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@cucumber/cucumber": "^9.3.0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#931d4db",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#ec52620",
"axios": "^1.7.4",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down
14 changes: 7 additions & 7 deletions e2e/tests/api-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"postinstall": "./install-dependencies.sh"
},
"dependencies": {
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#931d4db",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#ec52620",
"axios": "^1.7.4",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
Expand Down
14 changes: 7 additions & 7 deletions e2e/tests/ui-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/helpers/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function setUpTestContext(
name: context.team.name,
settings: {
homepage: context.team.settings?.homepage,
submissionEmail: context.team.submissionEmail,
submissionEmail: context.team.settings?.submissionEmail,
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@mui/lab": "5.0.0-alpha.170",
"@mui/material": "^5.15.10",
"@mui/utils": "^5.15.11",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#931d4db",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#ec52620",
"@opensystemslab/map": "1.0.0-alpha.2",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-bold": "^2.0.3",
Expand Down
16 changes: 8 additions & 8 deletions editor.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions editor.planx.uk/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
FlowStatus,
GovUKPayment,
NotifyPersonalisation,
Team,
TeamContactSettings,
} from "@opensystemslab/planx-core/types";
import { OT } from "@planx/graph/types";
import { useFormik } from "formik";
Expand Down Expand Up @@ -116,7 +116,7 @@ export interface AdminPanelData {
subdomain?: string;
planningDataEnabled: boolean;
article4sEnabled: string;
govnotifyPersonalisation?: NotifyPersonalisation;
govnotifyPersonalisation?: TeamContactSettings;
govpayEnabled: boolean;
sendToEmailAddress?: string;
bopsSubmissionURL?: string;
Expand Down

0 comments on commit eef7809

Please sign in to comment.