Scheduling infrastructure for absolutely everyone.
feat: move findAll to return arrays
Agusti Fernandez Pardo1241ae6cfc4a
diff --git a/pages/api/api-keys/index.ts b/pages/api/api-keys/index.tsindex 37a477f1bfd..5155c36c596 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<ResponseData>) {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.tsindex 121457759f5..1a105dd52d3 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<ResponseData>) {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 handlingres.status(400).json({ error: error });diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.tsindex f529fd6ed23..79f591c06bb 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<ResponseData>) {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 handlingres.status(400).json({ error: error });diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.tsindex 20b9a41a7e0..edfc31f1c11 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<ResponseData>) {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 handlingres.status(400).json({ error: error });diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.tsindex 534ebf828f9..348d6aca300 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<ResponseData>) {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 POSTres.status(405).json({ message: "Only GET Method allowed" });diff --git a/pages/api/teams/index.ts b/pages/api/teams/index.tsindex d00f092c998..0b57f216045 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<ResponseData>) {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 handlingres.status(400).json({ error: error });diff --git a/pages/api/users/index.ts b/pages/api/users/index.tsindex dd3665cf143..1644c3906be 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<Resconst { expiresAt } = apiInDb;// if (!apiInDb) res.status(400).json({ error: 'Your api key is not valid' });if (expiresAt && dateInPast(expiresAt, today)) {- console.log(apiInDb)try {- const users = await prisma.user.findMany();- res.status(200).json({ data: { ...users } });+ const data = await prisma.user.findMany();+ res.status(200).json({ data });} catch (error) {// FIXME: Add zod for validation/error handlingres.status(400).json({ error: error });diff --git a/tests/api-keys/[id]/api-key.id.delete.test.ts b/tests/api-keys/[id]/api-key.id.delete.test.tsindex 3bc2626a5de..fed838a16b2 100644--- a/tests/api-keys/[id]/api-key.id.delete.test.ts+++ b/tests/api-keys/[id]/api-key.id.delete.test.ts@@ -14,8 +14,6 @@ describe("DELETE /api/api-keys/[id]/delete with valid id as string returns an ap});// const apiKey = await prisma.apiKey.findUnique({ where: { id: req.query.id} });await handleDeleteApiKey(req, res);-- // console.log(res)expect(res._getStatusCode()).toBe(204);expect(JSON.parse(res._getData())).toEqual({message: `api-key with id: ${apiKey?.id} deleted successfully`});});