api data transformation

This commit is contained in:
Owen Rees
2023-06-20 08:55:56 +02:00
parent f1ef7cd3f2
commit 5aaa1deeff
3 changed files with 5 additions and 3 deletions
-1
View File
@@ -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
+5 -1
View File
@@ -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) {
-1
View File
@@ -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")