From abfcdc49f50151b7bf86973698aa969ac2f2d540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 1 Nov 2023 11:36:25 +0000 Subject: [PATCH] fix: Get session by pk for public client (with headers) --- api.planx.uk/saveAndReturn/validateSession.ts | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/api.planx.uk/saveAndReturn/validateSession.ts b/api.planx.uk/saveAndReturn/validateSession.ts index 739075ac0e..f1330e7c5c 100644 --- a/api.planx.uk/saveAndReturn/validateSession.ts +++ b/api.planx.uk/saveAndReturn/validateSession.ts @@ -227,6 +227,10 @@ async function diffLatestPublishedFlow({ return response.diff_latest_published_flow.data; } +interface FindSession { + session: Partial | null; +} + async function findSession({ sessionId, email, @@ -235,32 +239,26 @@ async function findSession({ email: string; }): Promise | undefined> { const headers = getSaveAndReturnPublicHeaders(sessionId, email); - const response: { lowcal_sessions: Partial[] } = - await $public.client.request( - gql` - query FindSession($sessionId: uuid!, $email: String!) { - lowcal_sessions( - where: { id: { _eq: $sessionId }, email: { _eq: $email } } - limit: 1 - ) { - flow_id - data - updated_at - lockedAt: locked_at - paymentRequests: payment_requests { - id - payeeName: payee_name - payeeEmail: payee_email - } + const response = await $public.client.request( + gql` + query FindSession($sessionId: uuid!, $email: String!) { + session: lowcal_sessions_by_pk(id: $id) { + flow_id + data + updated_at + lockedAt: locked_at + paymentRequests: payment_requests { + id + payeeName: payee_name + payeeEmail: payee_email } } - `, - { sessionId, email }, - headers, - ); - return response.lowcal_sessions.length - ? response.lowcal_sessions[0] - : undefined; + } + `, + { sessionId, email }, + headers, + ); + return response.session ?? undefined; } async function createAuditEntry(