Skip to content

Commit

Permalink
chore: Small tidy ups of API folder structure (#2379)
Browse files Browse the repository at this point in the history
* chore: Drop redundant session folder

* chore: Move Hasura to lib folder
  • Loading branch information
DafyddLlyr authored Nov 6, 2023
1 parent 9ed89c0 commit 840a109
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 70 deletions.
4 changes: 2 additions & 2 deletions api.planx.uk/inviteToPay/createPaymentSendEvents.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import supertest from "supertest";
import app from "../server";
import { createScheduledEvent } from "../hasura/metadata";
import { createScheduledEvent } from "../lib/hasura/metadata";
import { queryMock } from "../tests/graphqlQueryMock";
import { flowWithInviteToPay } from "../tests/mocks/inviteToPayData";

jest.mock("../hasura/metadata");
jest.mock("../lib/hasura/metadata");
const mockedCreateScheduledEvent = createScheduledEvent as jest.MockedFunction<
typeof createScheduledEvent
>;
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/inviteToPay/createPaymentSendEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { $api, $public } from "../client";
import {
ScheduledEventResponse,
createScheduledEvent,
} from "../hasura/metadata";
} from "../lib/hasura/metadata";
import { getMostRecentPublishedFlow } from "../helpers";
import { Flow, Node, Team } from "../types";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import supertest from "supertest";
import app from "../../../../server";
import { createScheduledEvent } from "../../../../hasura/metadata";
import { createScheduledEvent } from "../../../../lib/hasura/metadata";

const { post } = supertest(app);

jest.mock("../../../../hasura/metadata");
jest.mock("../../../../lib/hasura/metadata");
const mockedCreateScheduledEvent = createScheduledEvent as jest.MockedFunction<
typeof createScheduledEvent
>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addDays } from "date-fns";

import { createScheduledEvent } from "../../../../hasura/metadata";
import { createScheduledEvent } from "../../../../lib/hasura/metadata";
import {
DAYS_UNTIL_EXPIRY,
REMINDER_DAYS_FROM_EXPIRY,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { ValidatedRequestHandler } from "../../../../shared/middleware/validate";
import { ScheduledEventResponse } from "../../../../hasura/metadata";
import { ScheduledEventResponse } from "../../../../lib/hasura/metadata";

export const createSessionEventSchema = z.object({
body: z.object({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import supertest from "supertest";
import app from "../../../../server";
import { createScheduledEvent } from "../../../../hasura/metadata";
import { createScheduledEvent } from "../../../../lib/hasura/metadata";
import { CreatePaymentEvent } from "./schema";

const { post } = supertest(app);

jest.mock("../../../../hasura/metadata");
jest.mock("../../../../lib/hasura/metadata");
const mockedCreateScheduledEvent = createScheduledEvent as jest.MockedFunction<
typeof createScheduledEvent
>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addDays } from "date-fns";

import { createScheduledEvent } from "../../../../hasura/metadata";
import { createScheduledEvent } from "../../../../lib/hasura/metadata";
import {
DAYS_UNTIL_EXPIRY,
REMINDER_DAYS_FROM_EXPIRY,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { ValidatedRequestHandler } from "../../../../shared/middleware/validate";
import { ScheduledEventResponse } from "../../../../hasura/metadata";
import { ScheduledEventResponse } from "../../../../lib/hasura/metadata";

export const createPaymentEventSchema = z.object({
body: z.object({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runSQL } from "../../../../hasura/schema";
import { runSQL } from "../../../../lib/hasura/schema";
import { queryMock } from "../../../../tests/graphqlQueryMock";
import {
mockIds,
Expand All @@ -25,7 +25,7 @@ import {
deleteHasuraScheduledEventsForSubmittedSessions,
} from "./operations";

jest.mock("../../../../hasura/schema");
jest.mock("../../../../lib/hasura/schema");
const mockRunSQL = runSQL as jest.MockedFunction<typeof runSQL>;

const mockFindSession = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { gql } from "graphql-request";
import { subMonths } from "date-fns";

import { Operation, OperationResult, QueryResult } from "./types";
import { runSQL } from "../../../../hasura/schema";
import { getFilesForSession } from "../../../../session/files";
import { runSQL } from "../../../../lib/hasura/schema";
import { deleteFilesByURL } from "../../../../s3/deleteFile";
import { $api } from "../../../../client";
import { Passport } from "@opensystemslab/planx-core";

const RETENTION_PERIOD_MONTHS = 6;
export const getRetentionPeriod = () =>
Expand Down Expand Up @@ -97,7 +97,11 @@ export const deleteApplicationFiles: Operation = async () => {

const sessionIds = await getExpiredSessionIds();
for (const sessionId of sessionIds) {
const files = await getFilesForSession(sessionId);
const session = await $api.session.find(sessionId);
if (!session) {
throw Error(`Unable to find session matching id ${sessionId}`);
}
const files = new Passport(session.data.passport).files();
if (files.length) {
const deleted = await deleteFilesByURL(files);
deletedFiles.push(...deleted);
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/send/createSendEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from "express";
import {
ScheduledEventResponse,
createScheduledEvent,
} from "../hasura/metadata";
} from "../lib/hasura/metadata";

interface CombinedResponse {
bops?: ScheduledEventResponse;
Expand Down
41 changes: 0 additions & 41 deletions api.planx.uk/session/files.test.ts

This file was deleted.

12 changes: 0 additions & 12 deletions api.planx.uk/session/files.ts

This file was deleted.

0 comments on commit 840a109

Please sign in to comment.