Skip to content

Commit

Permalink
fix: Get session by pk for public client (with headers)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 1, 2023
1 parent 5c545c0 commit abfcdc4
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions api.planx.uk/saveAndReturn/validateSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ async function diffLatestPublishedFlow({
return response.diff_latest_published_flow.data;
}

interface FindSession {
session: Partial<LowCalSession> | null;
}

async function findSession({
sessionId,
email,
Expand All @@ -235,32 +239,26 @@ async function findSession({
email: string;
}): Promise<Partial<LowCalSession> | undefined> {
const headers = getSaveAndReturnPublicHeaders(sessionId, email);
const response: { lowcal_sessions: Partial<LowCalSession>[] } =
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<FindSession>(
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(
Expand Down

0 comments on commit abfcdc4

Please sign in to comment.