From 0b8c30074f5171d5bed1aa5f850ecbe0e58140ec 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 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/api.planx.uk/saveAndReturn/validateSession.ts b/api.planx.uk/saveAndReturn/validateSession.ts index 739075ac0e..e7203488a4 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,14 +239,11 @@ async function findSession({ email: string; }): Promise | undefined> { const headers = getSaveAndReturnPublicHeaders(sessionId, email); - const response: { lowcal_sessions: Partial[] } = - await $public.client.request( + const response = + await $public.client.request( gql` query FindSession($sessionId: uuid!, $email: String!) { - lowcal_sessions( - where: { id: { _eq: $sessionId }, email: { _eq: $email } } - limit: 1 - ) { + session: lowcal_sessions_by_pk(id: $id) { flow_id data updated_at @@ -258,9 +259,7 @@ async function findSession({ { sessionId, email }, headers, ); - return response.lowcal_sessions.length - ? response.lowcal_sessions[0] - : undefined; + return response.session ?? undefined; } async function createAuditEntry(