From 5aaa1deeff4bde5fa868a94c120aa593026d8f89 Mon Sep 17 00:00:00 2001 From: Owen Rees Date: Tue, 20 Jun 2023 08:55:56 +0200 Subject: [PATCH] api data transformation --- TODO | 1 - app/api/v1/tournaments/france/route.ts | 6 +++++- utils/dbDateOrdering.ts | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 4186a4e..aa654f0 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ - map and table mounts in tournament page <- get data to send to map/table ---------------------------------------------------------------- //TODO SRP for web and API data fetching -//TODO API should not display __v and _id should just be id //TODO about page //TODO contact page needs working mailer //TODO font size on mobile screen diff --git a/app/api/v1/tournaments/france/route.ts b/app/api/v1/tournaments/france/route.ts index 4310230..9b11c04 100644 --- a/app/api/v1/tournaments/france/route.ts +++ b/app/api/v1/tournaments/france/route.ts @@ -15,7 +15,11 @@ export async function GET() { const client = await clientPromise; const db = client.db("tournamentsFranceDB"); - const data = await dateOrderingFrance(db); + const results = await dateOrderingFrance(db); + const data = results.map(({ _id, __v, ...rest }) => ({ + id: _id, + ...rest, + })); return new Response(JSON.stringify(data), { status: 200, headers }); } catch (error) { diff --git a/utils/dbDateOrdering.ts b/utils/dbDateOrdering.ts index a420572..3a6ed06 100644 --- a/utils/dbDateOrdering.ts +++ b/utils/dbDateOrdering.ts @@ -3,7 +3,6 @@ import { Db } from "mongodb"; /** * Converts date from string into a date to allow ordering */ -// TODO remove the .toArray method as this is not SRP friendly export const dateOrderingFrance = async (db: Db) => { return await db .collection("tournaments")