feat: move findAll to return arrays
parent
19934d8c3a
commit
1241ae6cfc
|
@ -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" });
|
||||
}
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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" });
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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`});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue