Skip to content

Commit

Permalink
chore: Convert remain /admin endpoint to client (#2320)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Oct 17, 2023
1 parent 3bc7483 commit 34f5159
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
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

0 comments on commit 34f5159

Please sign in to comment.