Skip to content

Commit

Permalink
fix: FindSession
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 1, 2023
1 parent 5c545c0 commit 6ed792a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
52 changes: 25 additions & 27 deletions api.planx.uk/saveAndReturn/validateSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import type {
PublishedFlow,
Node,
} from "../types";
import { $api, $public, getClient } from "../client";
import { getSaveAndReturnPublicHeaders } from "./utils";
import { $api, getClient } from "../client";

export interface ValidationResponse {
message: string;
Expand Down Expand Up @@ -227,40 +226,39 @@ async function diffLatestPublishedFlow({
return response.diff_latest_published_flow.data;
}

interface FindSession {
sessions: Partial<LowCalSession>[];
}

async function findSession({
sessionId,
email,
}: {
sessionId: string;
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 $api.client.request<FindSession>(
gql`
query FindSession($sessionId: uuid!, $email: String!) {
sessions: 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
}
}
`,
{ sessionId, email },
headers,
);
return response.lowcal_sessions.length
? response.lowcal_sessions[0]
: undefined;
}
`,
{ sessionId, email },
);
return response.sessions.length ? response.sessions[0] : undefined;
}

async function createAuditEntry(
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/tests/mocks/saveAndReturnMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const mockLowcalSession: LowCalSession = {
export const mockFindSession = (breadcrumbs = {}) => ({
name: "FindSession",
data: {
lowcal_sessions: [
sessions: [
{
...mockLowcalSession,
data: {
Expand All @@ -92,7 +92,7 @@ export const mockFindSession = (breadcrumbs = {}) => ({
export const mockNotFoundSession = {
name: "FindSession",
data: {
lowcal_sessions: [],
sessions: [],
},
variables: {
sessionId: "not-found-id",
Expand Down

0 comments on commit 6ed792a

Please sign in to comment.