Skip to content

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.ts
index 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.ts
index 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 handling
res.status(400).json({ error: error });
diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.ts
index 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 handling
res.status(400).json({ error: error });
diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts
index 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 handling
res.status(400).json({ error: error });
diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts
index 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 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 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 handling
res.status(400).json({ error: error });
diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts
index 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<Res
const { 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 handling
res.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.ts
index 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`});
});