Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Convert remaining /admin endpoints to $api client #2320

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions api.planx.uk/admin/session/csv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stringify } from "csv-stringify";
import { NextFunction, Request, Response } from "express";
import { getClient } from "../../client";
import { $api } from "../../client";

/**
* @swagger
Expand All @@ -26,8 +26,7 @@ export async function getCSVData(
next: NextFunction,
) {
try {
const $client = getClient();
const responses = await $client.export.csvData(req.params.sessionId);
const responses = await $api.export.csvData(req.params.sessionId);

if (req.query?.download) {
stringify(responses, {
Expand Down Expand Up @@ -70,8 +69,7 @@ export async function getRedactedCSVData(
next: NextFunction,
) {
try {
const $client = getClient();
const redactedResponses = await $client.export.csvDataRedacted(
const redactedResponses = await $api.export.csvDataRedacted(
req.params.sessionId,
);

Expand Down
12 changes: 5 additions & 7 deletions api.planx.uk/admin/session/html.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateApplicationHTML } from "@opensystemslab/planx-core";
import { getClient } from "../../client";
import { $api } from "../../client";
import type { RequestHandler } from "express";
import type { PlanXExportData } from "@opensystemslab/planx-core/types";

Expand All @@ -20,11 +20,10 @@ type HTMLExportHandler = RequestHandler<{ sessionId: string }, string>;
*/
export const getHTMLExport: HTMLExportHandler = async (req, res, next) => {
try {
const $client = getClient();
const session = await $client.session.find(req.params.sessionId);
const session = await $api.session.find(req.params.sessionId);
if (!session) throw Error(`Unable to find session ${req.params.sessionId}`);

const responses = await $client.export.csvData(req.params.sessionId);
const responses = await $api.export.csvData(req.params.sessionId);
const boundingBox =
session.data.passport.data["property.boundary.site.buffered"];

Expand Down Expand Up @@ -61,11 +60,10 @@ export const getRedactedHTMLExport: HTMLExportHandler = async (
next,
) => {
try {
const $client = getClient();
const session = await $client.session.find(req.params.sessionId);
const session = await $api.session.find(req.params.sessionId);
if (!session) throw Error(`Unable to find session ${req.params.sessionId}`);

const redactedResponses = await $client.export.csvDataRedacted(
const redactedResponses = await $api.export.csvDataRedacted(
req.params.sessionId,
);
const boundingBox =
Expand Down
Loading