Skip to content

Commit

Permalink
rebase and bump planx-core
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Jul 12, 2024
2 parents 44db0f4 + 80ae221 commit ff93a74
Show file tree
Hide file tree
Showing 41 changed files with 321 additions and 147 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 @@ -47,7 +47,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
60 changes: 35 additions & 25 deletions api.planx.uk/modules/pay/service/inviteToPay/sendPaymentEmail.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { formatRawProjectTypes } from "@opensystemslab/planx-core";
import type { PaymentRequest } from "@opensystemslab/planx-core/types";
import type { PaymentRequest, Team } from "@opensystemslab/planx-core/types";
import { gql } from "graphql-request";
import {
Template,
getClientForTemplate,
sendEmail,
} from "../../../../lib/notify";
import { InviteToPayNotifyConfig, Team } from "../../../../types";
import { InviteToPayNotifyConfig } from "../../../../types";
import {
calculateExpiryDate,
getServiceLink,
Expand Down Expand Up @@ -74,7 +74,7 @@ const validatePaymentRequest = async (
name
slug
domain
notifyPersonalisation: notify_personalisation
settings: team_settings
}
}
}
Expand Down Expand Up @@ -107,28 +107,38 @@ const validatePaymentRequest = async (
const getInviteToPayNotifyConfig = (
session: SessionDetails,
paymentRequest: PaymentRequest,
): 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:
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),
},
});
): 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:
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,10 +1,10 @@
import { formatRawProjectTypes } from "@opensystemslab/planx-core";
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 } 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 @@ -18,7 +18,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 @@ -65,7 +65,7 @@ const validateRequest = async (
teams(where: { slug: { _eq: $teamSlug } }) {
slug
name
notifyPersonalisation: notify_personalisation
settings: team_settings
domain
}
}
Expand Down Expand Up @@ -94,7 +94,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
14 changes: 9 additions & 5 deletions api.planx.uk/modules/saveAndReturn/service/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { formatRawProjectTypes } from "@opensystemslab/planx-core";
import { SiteAddress } from "@opensystemslab/planx-core/types";
import { SiteAddress, Team } from "@opensystemslab/planx-core/types";
import { addDays, format } from "date-fns";
import { gql } from "graphql-request";

import { $api } from "../../../client";
import { Template, getClientForTemplate, sendEmail } from "../../../lib/notify";
import { LowCalSession, Team } from "../../../types";
import { LowCalSession } from "../../../types";

const DAYS_UNTIL_EXPIRY = 28;
const REMINDER_DAYS_FROM_EXPIRY = [7, 1];
Expand Down Expand Up @@ -60,7 +61,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 @@ -98,7 +99,7 @@ const validateSingleSessionRequest = async (
team {
name
slug
notifyPersonalisation: notify_personalisation
settings: team_settings
domain
}
}
Expand Down Expand Up @@ -174,7 +175,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#0c256f1",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#eb3b635",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand Down
39 changes: 30 additions & 9 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
Loading

0 comments on commit ff93a74

Please sign in to comment.