From 1241ae6cfc4adfaa1ef474a15b9b84d95a0930dc Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Mon, 28 Mar 2022 16:05:00 +0200 Subject: [PATCH] feat: move findAll to return arrays --- pages/api/api-keys/index.ts | 4 ++-- pages/api/attendees/index.ts | 4 ++-- pages/api/availabilities/index.ts | 4 ++-- pages/api/bookings/index.ts | 4 ++-- pages/api/event-types/index.ts | 4 ++-- pages/api/teams/index.ts | 4 ++-- pages/api/users/index.ts | 5 ++--- tests/api-keys/[id]/api-key.id.delete.test.ts | 2 -- 8 files changed, 14 insertions(+), 17 deletions(-) diff --git a/pages/api/api-keys/index.ts b/pages/api/api-keys/index.ts index 37a477f1bf..5155c36c59 100644 --- a/pages/api/api-keys/index.ts +++ b/pages/api/api-keys/index.ts @@ -12,7 +12,7 @@ type ResponseData = { export default async function apiKeys(req: NextApiRequest, res: NextApiResponse) { const { method } = req; if (method === "GET") { - const apiKeys = await prisma.apiKey.findMany({}); - res.status(200).json({ data: { ...apiKeys } }); + const data = await prisma.apiKey.findMany({}); + res.status(200).json({ data }); } else res.status(405).json({ message: "Only GET Method allowed" }); } diff --git a/pages/api/attendees/index.ts b/pages/api/attendees/index.ts index 121457759f..1a105dd52d 100644 --- a/pages/api/attendees/index.ts +++ b/pages/api/attendees/index.ts @@ -10,8 +10,8 @@ type ResponseData = { export default async function attendee(req: NextApiRequest, res: NextApiResponse) { try { - const attendees = await prisma.attendee.findMany(); - res.status(200).json({ data: { ...attendees } }); + const data = await prisma.attendee.findMany(); + res.status(200).json({ data }); } catch (error) { // FIXME: Add zod for validation/error handling res.status(400).json({ error: error }); diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.ts index f529fd6ed2..79f591c06b 100644 --- a/pages/api/availabilities/index.ts +++ b/pages/api/availabilities/index.ts @@ -10,8 +10,8 @@ type ResponseData = { export default async function availability(req: NextApiRequest, res: NextApiResponse) { try { - const availabilities = await prisma.availability.findMany(); - res.status(200).json({ data: { ...availabilities } }); + const data = await prisma.availability.findMany(); + res.status(200).json({ data }); } catch (error) { // FIXME: Add zod for validation/error handling res.status(400).json({ error: error }); diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts index 20b9a41a7e..edfc31f1c1 100644 --- a/pages/api/bookings/index.ts +++ b/pages/api/bookings/index.ts @@ -10,8 +10,8 @@ type ResponseData = { export default async function booking(req: NextApiRequest, res: NextApiResponse) { try { - const bookings = await prisma.booking.findMany(); - res.status(200).json({ data: { ...bookings } }); + const data = await prisma.booking.findMany(); + res.status(200).json({ data }); } catch (error) { // FIXME: Add zod for validation/error handling res.status(400).json({ error: error }); diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 534ebf828f..348d6aca30 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -12,8 +12,8 @@ type ResponseData = { export default async function eventType(req: NextApiRequest, res: NextApiResponse) { const { method } = req; if (method === "GET") { - const eventTypes = await prisma.eventType.findMany(); - res.status(200).json({ data: { ...eventTypes } }); + const data = await prisma.eventType.findMany(); + res.status(200).json({ data }); } else { // Reject any other HTTP method than POST res.status(405).json({ message: "Only GET Method allowed" }); diff --git a/pages/api/teams/index.ts b/pages/api/teams/index.ts index d00f092c99..0b57f21604 100644 --- a/pages/api/teams/index.ts +++ b/pages/api/teams/index.ts @@ -10,8 +10,8 @@ type ResponseData = { export default async function team(req: NextApiRequest, res: NextApiResponse) { try { - const teams = await prisma.team.findMany(); - res.status(200).json({ data: { ...teams } }); + const data = await prisma.team.findMany(); + res.status(200).json({ data }); } catch (error) { // FIXME: Add zod for validation/error handling res.status(400).json({ error: error }); diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts index dd3665cf14..1644c3906b 100644 --- a/pages/api/users/index.ts +++ b/pages/api/users/index.ts @@ -23,10 +23,9 @@ export default async function user(req: NextApiRequest, res: NextApiResponse