diff --git a/api.planx.uk/admin/session/bops.ts b/api.planx.uk/admin/session/bops.ts index 1bf26828be..020cf980ec 100644 --- a/api.planx.uk/admin/session/bops.ts +++ b/api.planx.uk/admin/session/bops.ts @@ -1,5 +1,5 @@ import { Request, Response, NextFunction } from "express"; -import { $admin } from "../../client"; +import { getClient } from "../../client"; /** * @swagger @@ -20,7 +20,8 @@ export const getBOPSPayload = async ( next: NextFunction, ) => { try { - const { exportData } = await $admin.export.bopsPayload( + const $client = getClient(); + const { exportData } = await $client.export.bopsPayload( req.params.sessionId, ); res.set("content-type", "application/json"); diff --git a/api.planx.uk/admin/session/csv.ts b/api.planx.uk/admin/session/csv.ts index e99659678f..57d485482c 100644 --- a/api.planx.uk/admin/session/csv.ts +++ b/api.planx.uk/admin/session/csv.ts @@ -1,6 +1,6 @@ import { stringify } from "csv-stringify"; import { NextFunction, Request, Response } from "express"; -import { $admin } from "../../client"; +import { getClient } from "../../client"; /** * @swagger @@ -26,7 +26,8 @@ export async function getCSVData( next: NextFunction, ) { try { - const { responses } = await $admin.export.csvData(req.params.sessionId); + const $client = getClient(); + const { responses } = await $client.export.csvData(req.params.sessionId); if (req.query?.download) { stringify(responses, { @@ -69,7 +70,8 @@ export async function getRedactedCSVData( next: NextFunction, ) { try { - const { redactedResponses } = await $admin.export.csvData( + const $client = getClient(); + const { redactedResponses } = await $client.export.csvData( req.params.sessionId, ); diff --git a/api.planx.uk/admin/session/html.ts b/api.planx.uk/admin/session/html.ts index 01a0f89b7a..c4e4a3d990 100644 --- a/api.planx.uk/admin/session/html.ts +++ b/api.planx.uk/admin/session/html.ts @@ -1,5 +1,5 @@ import { generateApplicationHTML } from "@opensystemslab/planx-core"; -import { $admin } from "../../client"; +import { getClient } from "../../client"; import type { RequestHandler } from "express"; import type { PlanXExportData } from "@opensystemslab/planx-core/types"; @@ -20,10 +20,11 @@ type HTMLExportHandler = RequestHandler<{ sessionId: string }, string>; */ export const getHTMLExport: HTMLExportHandler = async (req, res, next) => { try { - const session = await $admin.session.find(req.params.sessionId); + const $client = getClient(); + const session = await $client.session.find(req.params.sessionId); if (!session) throw Error(`Unable to find session ${req.params.sessionId}`); - const { responses } = await $admin.export.csvData(req.params.sessionId); + const { responses } = await $client.export.csvData(req.params.sessionId); const boundingBox = session.data.passport.data["property.boundary.site.buffered"]; @@ -60,10 +61,11 @@ export const getRedactedHTMLExport: HTMLExportHandler = async ( next, ) => { try { - const session = await $admin.session.find(req.params.sessionId); + const $client = getClient(); + const session = await $client.session.find(req.params.sessionId); if (!session) throw Error(`Unable to find session ${req.params.sessionId}`); - const { redactedResponses } = await $admin.export.csvData( + const { redactedResponses } = await $client.export.csvData( req.params.sessionId, ); const boundingBox = diff --git a/api.planx.uk/inviteToPay/sendConfirmationEmail.ts b/api.planx.uk/inviteToPay/sendConfirmationEmail.ts index ea6e50c80c..42f5d93f44 100644 --- a/api.planx.uk/inviteToPay/sendConfirmationEmail.ts +++ b/api.planx.uk/inviteToPay/sendConfirmationEmail.ts @@ -1,4 +1,4 @@ -import { $admin } from "../client"; +import { $public, $admin } from "../client"; import { sendEmail } from "../notify"; import { gql } from "graphql-request"; import { convertSlugToName } from "../saveAndReturn/utils"; @@ -8,7 +8,7 @@ export async function sendAgentAndPayeeConfirmationEmail(sessionId: string) { const { personalisation, applicantEmail, payeeEmail, projectTypes } = await getDataForPayeeAndAgentEmails(sessionId); const projectType = projectTypes.length - ? await $admin.formatRawProjectTypes(projectTypes) + ? await $public.formatRawProjectTypes(projectTypes) : "Project type not submitted"; const config: AgentAndPayeeSubmissionNotifyConfig = { personalisation: { diff --git a/api.planx.uk/inviteToPay/sendPaymentEmail.ts b/api.planx.uk/inviteToPay/sendPaymentEmail.ts index d9b884f57b..96c6e31e99 100644 --- a/api.planx.uk/inviteToPay/sendPaymentEmail.ts +++ b/api.planx.uk/inviteToPay/sendPaymentEmail.ts @@ -8,7 +8,7 @@ import { Template, getClientForTemplate, sendEmail } from "../notify"; import { InviteToPayNotifyConfig } from "../types"; import { Team } from "../types"; import type { PaymentRequest } from "@opensystemslab/planx-core/types"; -import { $admin } from "../client"; +import { $public } from "../client"; interface SessionDetails { email: string; @@ -118,7 +118,7 @@ const getInviteToPayNotifyConfig = async ( ).title, fee: getFee(paymentRequest), projectType: - (await $admin.formatRawProjectTypes( + (await $public.formatRawProjectTypes( paymentRequest.sessionPreviewData?.["proposal.projectType"] as string[], )) || "Project type not submitted", serviceName: convertSlugToName(session.flow.slug), diff --git a/api.planx.uk/modules/team/controller.ts b/api.planx.uk/modules/team/controller.ts index e6eabd9e8c..03d12aa738 100644 --- a/api.planx.uk/modules/team/controller.ts +++ b/api.planx.uk/modules/team/controller.ts @@ -1,5 +1,5 @@ import { z } from "zod"; -import { $admin } from "../../client"; +import { getClient } from "../../client"; import { ValidatedRequestHandler } from "../../shared/middleware/validate"; interface TeamMemberResponse { @@ -39,7 +39,8 @@ export const addMember: UpsertMember = async (req, res) => { const { teamId } = req.params; const { userId, role } = req.body; - const isSuccess = await $admin.team.addMember({ teamId, userId, role }); + const $client = getClient(); + const isSuccess = await $client.team.addMember({ teamId, userId, role }); if (!isSuccess) return res.status(500).json({ message: "Failed to add member to team" }); @@ -51,7 +52,8 @@ export const changeMemberRole: UpsertMember = async (req, res) => { const { teamId } = req.params; const { userId, role } = req.body; - const isSuccess = await $admin.team.changeMemberRole({ + const $client = getClient(); + const isSuccess = await $client.team.changeMemberRole({ teamId, userId, role, @@ -67,7 +69,8 @@ export const removeMember: RemoveMember = async (req, res) => { const { teamId } = req.params; const { userId } = req.body; - const isSuccess = await $admin.team.removeMember({ teamId, userId }); + const $client = getClient(); + const isSuccess = await $client.team.removeMember({ teamId, userId }); if (!isSuccess) return res diff --git a/api.planx.uk/saveAndReturn/resumeApplication.ts b/api.planx.uk/saveAndReturn/resumeApplication.ts index 1222e0efb2..292636fb79 100644 --- a/api.planx.uk/saveAndReturn/resumeApplication.ts +++ b/api.planx.uk/saveAndReturn/resumeApplication.ts @@ -5,7 +5,7 @@ import { LowCalSession, Team } from "../types"; import { convertSlugToName, getResumeLink, calculateExpiryDate } from "./utils"; import { sendEmail } from "../notify"; import type { SiteAddress } from "@opensystemslab/planx-core/types"; -import { $admin } from "../client"; +import { $public } from "../client"; /** * Send a "Resume" email to an applicant which list all open applications for a given council (team) @@ -121,7 +121,7 @@ const buildContentFromSessions = async ( const address: SiteAddress | undefined = session.data?.passport?.data?._address; const addressLine = address?.single_line_address || address?.title; - const projectType = await $admin.formatRawProjectTypes( + const projectType = await $public.formatRawProjectTypes( session.data?.passport?.data?.["proposal.projectType"], ); const resumeLink = getResumeLink(session, team, session.flow.slug); diff --git a/api.planx.uk/saveAndReturn/utils.ts b/api.planx.uk/saveAndReturn/utils.ts index b64e75af55..2de72f806f 100644 --- a/api.planx.uk/saveAndReturn/utils.ts +++ b/api.planx.uk/saveAndReturn/utils.ts @@ -4,7 +4,7 @@ import { gql } from "graphql-request"; import { adminGraphQLClient as adminClient } from "../hasura"; import { LowCalSession, Team } from "../types"; import { Template, getClientForTemplate, sendEmail } from "../notify"; -import { $admin } from "../client"; +import { $public } from "../client"; const DAYS_UNTIL_EXPIRY = 28; const REMINDER_DAYS_FROM_EXPIRY = [7, 1]; @@ -145,7 +145,7 @@ const getSessionDetails = async ( session.data.passport?.data?.["proposal.projectType"]; const projectTypes = passportProtectTypes && - (await $admin.formatRawProjectTypes(passportProtectTypes)); + (await $public.formatRawProjectTypes(passportProtectTypes)); const address: SiteAddress | undefined = session.data?.passport?.data?._address; const addressLine = address?.single_line_address || address?.title;