Skip to content

Commit

Permalink
feat: Read from new team_settings table (#3391)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Jul 11, 2024
1 parent b8da414 commit 67b15da
Show file tree
Hide file tree
Showing 34 changed files with 194 additions and 141 deletions.
9 changes: 2 additions & 7 deletions api.planx.uk/modules/admin/session/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ import {
GovUKPayment,
PaymentRequest,
Session,
Team,
} from "@opensystemslab/planx-core/types";
import { NextFunction, Request, Response } from "express";
import { gql } from "graphql-request";

import {
Breadcrumb,
Flow,
LowCalSession,
Passport,
Team,
} from "../../../types";
import { Breadcrumb, Flow, LowCalSession, Passport } from "../../../types";
import { $api } from "../../../client";

/**
Expand Down
3 changes: 2 additions & 1 deletion api.planx.uk/modules/flows/moveFlow/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { gql } from "graphql-request";
import { Flow, Team } from "../../../types";
import { Flow } from "../../../types";
import { $public, getClient } from "../../../client";
import { Team } from "@opensystemslab/planx-core/types";

export const moveFlow = async (flowId: string, teamSlug: string) => {
const team = await $public.team.getBySlug(teamSlug);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentType } from "@opensystemslab/planx-core/types";
import { ComponentType, Team } from "@opensystemslab/planx-core/types";
import { NextFunction, Request, Response } from "express";
import { gql } from "graphql-request";
import {
Expand All @@ -7,7 +7,7 @@ import {
} from "../../../../lib/hasura/metadata";
import { $api, $public } from "../../../../client";
import { getMostRecentPublishedFlow } from "../../../../helpers";
import { Flow, Node, Team } from "../../../../types";
import { Flow, Node } from "../../../../types";

enum Destination {
BOPS = "bops",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ async function getDataForPayeeAndAgentEmails(
flow {
slug
team {
notifyPersonalisation: notify_personalisation
notifyPersonalisation: team_settings {
helpEmail: help_email
helpPhone: help_phone
emailReplyToId: email_reply_to_id
helpOpeningHours: help_opening_hours
}
}
}
paymentRequests: payment_requests(
Expand Down
59 changes: 34 additions & 25 deletions api.planx.uk/modules/pay/service/inviteToPay/sendPaymentEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
sendEmail,
} from "../../../../lib/notify";
import { InviteToPayNotifyConfig } from "../../../../types";
import { Team } from "../../../../types";
import type { PaymentRequest } from "@opensystemslab/planx-core/types";
import type { PaymentRequest, Team } from "@opensystemslab/planx-core/types";
import { $public } from "../../../../client";

interface SessionDetails {
Expand Down Expand Up @@ -75,7 +74,7 @@ const validatePaymentRequest = async (
name
slug
domain
notifyPersonalisation: notify_personalisation
settings: team_settings
}
}
}
Expand Down Expand Up @@ -108,28 +107,38 @@ const validatePaymentRequest = async (
const getInviteToPayNotifyConfig = async (
session: SessionDetails,
paymentRequest: PaymentRequest,
): Promise<InviteToPayNotifyConfig> => ({
personalisation: {
...session.flow.team.notifyPersonalisation,
sessionId: paymentRequest.sessionId,
paymentRequestId: paymentRequest.id,
payeeEmail: paymentRequest.payeeEmail,
payeeName: paymentRequest.payeeName,
agentName: paymentRequest.applicantName,
address: (
paymentRequest.sessionPreviewData?._address as Record<"title", string>
).title,
fee: getFee(paymentRequest),
projectType:
(await $public.formatRawProjectTypes(
paymentRequest.sessionPreviewData?.["proposal.projectType"] as string[],
)) || "Project type not submitted",
serviceName: session.flow.name,
serviceLink: getServiceLink(session.flow.team, session.flow.slug),
expiryDate: calculateExpiryDate(paymentRequest.createdAt),
paymentLink: getPaymentLink(session, paymentRequest),
},
});
): Promise<InviteToPayNotifyConfig> => {
const flow = session.flow;
const { settings } = session.flow.team;

return {
personalisation: {
helpEmail: settings.helpEmail,
helpPhone: settings.helpPhone,
emailReplyToId: settings.emailReplyToId,
helpOpeningHours: settings.helpOpeningHours,
sessionId: paymentRequest.sessionId,
paymentRequestId: paymentRequest.id,
payeeEmail: paymentRequest.payeeEmail,
payeeName: paymentRequest.payeeName,
agentName: paymentRequest.applicantName,
address: (
paymentRequest.sessionPreviewData?._address as Record<"title", string>
).title,
fee: getFee(paymentRequest),
projectType:
(await $public.formatRawProjectTypes(
paymentRequest.sessionPreviewData?.[
"proposal.projectType"
] as string[],
)) || "Project type not submitted",
serviceName: session.flow.name,
serviceLink: getServiceLink(flow.team, flow.slug),
expiryDate: calculateExpiryDate(paymentRequest.createdAt),
paymentLink: getPaymentLink(session, paymentRequest),
},
};
};

const getFee = (paymentRequest: PaymentRequest) => {
const toPounds = (pence: number) => pence / 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LowCalSession, Team } from "../../../types";
import { LowCalSession } from "../../../types";
import supertest from "supertest";
import app from "../../../server";
import { queryMock } from "../../../tests/graphqlQueryMock";
Expand All @@ -8,6 +8,7 @@ import {
} from "../../../tests/mocks/saveAndReturnMocks";
import { buildContentFromSessions } from "./resumeApplication";
import { PartialDeep } from "type-fest";
import { Team } from "@opensystemslab/planx-core/types";

const ENDPOINT = "/resume-application";
const TEST_EMAIL = "[email protected]";
Expand Down
13 changes: 8 additions & 5 deletions api.planx.uk/modules/saveAndReturn/service/resumeApplication.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { SiteAddress } from "@opensystemslab/planx-core/types";
import type { SiteAddress, Team } from "@opensystemslab/planx-core/types";
import { differenceInDays } from "date-fns";
import { gql } from "graphql-request";
import { $api, $public } from "../../../client";
import { sendEmail } from "../../../lib/notify";
import { LowCalSession, Team } from "../../../types";
import { LowCalSession } from "../../../types";
import { DAYS_UNTIL_EXPIRY, calculateExpiryDate, getResumeLink } from "./utils";

/**
Expand All @@ -17,7 +17,7 @@ const resumeApplication = async (teamSlug: string, email: string) => {
const config = {
personalisation: await getPersonalisation(sessions, team),
reference: null,
emailReplyToId: team.notifyPersonalisation.emailReplyToId,
emailReplyToId: team.settings.emailReplyToId,
};
const response = await sendEmail("resume", email, config);
return response;
Expand Down Expand Up @@ -64,7 +64,7 @@ const validateRequest = async (
teams(where: { slug: { _eq: $teamSlug } }) {
slug
name
notifyPersonalisation: notify_personalisation
settings: team_settings
domain
}
}
Expand Down Expand Up @@ -93,7 +93,10 @@ const getPersonalisation = async (sessions: LowCalSession[], team: Team) => {
return {
teamName: team.name,
content: await buildContentFromSessions(sessions, team),
...team.notifyPersonalisation,
helpEmail: team.settings.helpEmail,
helpPhone: team.settings.helpPhone,
helpOpeningHours: team.settings.helpOpeningHours,
emailReplyToId: team.settings.emailReplyToId,
};
};

Expand Down
3 changes: 2 additions & 1 deletion api.planx.uk/modules/saveAndReturn/service/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Team } from "@opensystemslab/planx-core/types";
import { queryMock } from "../../../tests/graphqlQueryMock";
import { LowCalSession, LowCalSessionData, Team } from "../../../types";
import { LowCalSession, LowCalSessionData } from "../../../types";
import {
getResumeLink,
getSessionDetails,
Expand Down
13 changes: 8 additions & 5 deletions api.planx.uk/modules/saveAndReturn/service/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SiteAddress } from "@opensystemslab/planx-core/types";
import { SiteAddress, Team } from "@opensystemslab/planx-core/types";
import { format, addDays } from "date-fns";
import { gql } from "graphql-request";
import { LowCalSession, Team } from "../../../types";
import { LowCalSession } from "../../../types";
import { Template, getClientForTemplate, sendEmail } from "../../../lib/notify";
import { $api, $public } from "../../../client";

Expand Down Expand Up @@ -59,7 +59,7 @@ const sendSingleApplicationEmail = async ({
const config = {
personalisation: getPersonalisation(session, flowSlug, flowName, team),
reference: null,
emailReplyToId: team.notifyPersonalisation.emailReplyToId,
emailReplyToId: team.settings.emailReplyToId,
};
const firstSave = !session.hasUserSaved;
if (firstSave && !session.submittedAt)
Expand Down Expand Up @@ -97,7 +97,7 @@ const validateSingleSessionRequest = async (
team {
name
slug
notifyPersonalisation: notify_personalisation
settings: team_settings
domain
}
}
Expand Down Expand Up @@ -176,7 +176,10 @@ const getPersonalisation = (
serviceName: flowName,
teamName: team.name,
sessionId: session.id,
...team.notifyPersonalisation,
helpEmail: team.settings.helpEmail,
helpPhone: team.settings.helpPhone,
helpOpeningHours: team.settings.helpOpeningHours,
emailReplyToId: team.settings.emailReplyToId,
...session,
};
};
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/send/email/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe(`sending an application by email to a planning office`, () => {
teams: [
{
sendToEmail: "[email protected]",
notifyPersonalisation: { emailReplyToId: "abc123" },
settings: { emailReplyToId: "abc123" },
},
],
},
Expand Down Expand Up @@ -153,7 +153,7 @@ describe(`sending an application by email to a planning office`, () => {
teams: [
{
sendToEmail: null,
notifyPersonalisation: { emailReplyToId: "abc123" },
settings: { emailReplyToId: "abc123" },
},
],
},
Expand Down
7 changes: 6 additions & 1 deletion api.planx.uk/modules/send/email/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export async function getTeamEmailSettings(localAuthority: string) {
query GetTeamEmailSettings($slug: String) {
teams(where: { slug: { _eq: $slug } }) {
sendToEmail: submission_email
notifyPersonalisation: notify_personalisation
notifyPersonalisation: team_settings {
helpEmail: help_email
helpPhone: help_phone
emailReplyToId: email_reply_to_id
helpOpeningHours: help_opening_hours
}
}
}
`,
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 @@ -5,7 +5,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@airbrake/node": "^2.1.8",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#b43b268",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#75127e6",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand Down
8 changes: 4 additions & 4 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 api.planx.uk/tests/mocks/inviteToPayData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const validPaymentRequest = {
name: "Buckinghamshire",
slug: "buckinghamshire",
domain: "planningservices.buckinghamshire.gov.uk",
notifyPersonalisation: {
settings: {
helpEmail: "[email protected]",
helpPhone: "123",
helpOpeningHours: "9a-5p",
Expand Down
5 changes: 3 additions & 2 deletions api.planx.uk/tests/mocks/saveAndReturnMocks.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { v4 as uuidV4 } from "uuid";
import type { LowCalSession, Flow } from "../../types";
import { Team } from "@opensystemslab/planx-core/types";

export const mockTeam = {
id: 1,
slug: "test-team",
name: "Test Team",
notifyPersonalisation: {
settings: {
helpEmail: "[email protected]",
helpPhone: "(01234) 567890",
helpOpeningHours: "Monday - Friday, 9am - 5pm",
emailReplyToId: "727d48fa-cb8a-42f9-b8b2-55032f3bb451",
},
};
} as Team;

export const mockFlow: Flow = {
id: "dcfd4f07-76da-4b67-9822-2aca92b27551",
Expand Down
16 changes: 1 addition & 15 deletions api.planx.uk/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PaymentRequest } from "@opensystemslab/planx-core/dist/types";
import { GovUKPayment } from "@opensystemslab/planx-core/types";
import { GovUKPayment, Team } from "@opensystemslab/planx-core/types";

/**
* @deprecated Migrating to Node from planx-core
Expand Down Expand Up @@ -49,20 +49,6 @@ export interface UserData {

export type Breadcrumb = Record<string, UserData>;

export interface Team {
id: number;
slug: string;
name: string;
domain?: string;
boundaryBBox?: object;
notifyPersonalisation: {
helpEmail: string;
helpPhone: string;
helpOpeningHours: string;
emailReplyToId: string;
};
}

export interface Passport {
data: Record<string, any>;
}
Expand Down
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#b43b268",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#75127e6",
"axios": "^1.6.8",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down
8 changes: 4 additions & 4 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.

Loading

0 comments on commit 67b15da

Please sign in to comment.