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>) {
|
export default async function apiKeys(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||||
const { method } = req;
|
const { method } = req;
|
||||||
if (method === "GET") {
|
if (method === "GET") {
|
||||||
const apiKeys = await prisma.apiKey.findMany({});
|
const data = await prisma.apiKey.findMany({});
|
||||||
res.status(200).json({ data: { ...apiKeys } });
|
res.status(200).json({ data });
|
||||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
} 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>) {
|
export default async function attendee(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||||
try {
|
try {
|
||||||
const attendees = await prisma.attendee.findMany();
|
const data = await prisma.attendee.findMany();
|
||||||
res.status(200).json({ data: { ...attendees } });
|
res.status(200).json({ data });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// FIXME: Add zod for validation/error handling
|
// FIXME: Add zod for validation/error handling
|
||||||
res.status(400).json({ error: error });
|
res.status(400).json({ error: error });
|
||||||
|
|
|
@ -10,8 +10,8 @@ type ResponseData = {
|
||||||
|
|
||||||
export default async function availability(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
export default async function availability(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||||
try {
|
try {
|
||||||
const availabilities = await prisma.availability.findMany();
|
const data = await prisma.availability.findMany();
|
||||||
res.status(200).json({ data: { ...availabilities } });
|
res.status(200).json({ data });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// FIXME: Add zod for validation/error handling
|
// FIXME: Add zod for validation/error handling
|
||||||
res.status(400).json({ error: error });
|
res.status(400).json({ error: error });
|
||||||
|
|
|
@ -10,8 +10,8 @@ type ResponseData = {
|
||||||
|
|
||||||
export default async function booking(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
export default async function booking(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||||
try {
|
try {
|
||||||
const bookings = await prisma.booking.findMany();
|
const data = await prisma.booking.findMany();
|
||||||
res.status(200).json({ data: { ...bookings } });
|
res.status(200).json({ data });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// FIXME: Add zod for validation/error handling
|
// FIXME: Add zod for validation/error handling
|
||||||
res.status(400).json({ error: error });
|
res.status(400).json({ error: error });
|
||||||
|
|
|
@ -12,8 +12,8 @@ type ResponseData = {
|
||||||
export default async function eventType(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
export default async function eventType(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||||
const { method } = req;
|
const { method } = req;
|
||||||
if (method === "GET") {
|
if (method === "GET") {
|
||||||
const eventTypes = await prisma.eventType.findMany();
|
const data = await prisma.eventType.findMany();
|
||||||
res.status(200).json({ data: { ...eventTypes } });
|
res.status(200).json({ data });
|
||||||
} else {
|
} else {
|
||||||
// Reject any other HTTP method than POST
|
// Reject any other HTTP method than POST
|
||||||
res.status(405).json({ message: "Only GET Method allowed" });
|
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>) {
|
export default async function team(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||||
try {
|
try {
|
||||||
const teams = await prisma.team.findMany();
|
const data = await prisma.team.findMany();
|
||||||
res.status(200).json({ data: { ...teams } });
|
res.status(200).json({ data });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// FIXME: Add zod for validation/error handling
|
// FIXME: Add zod for validation/error handling
|
||||||
res.status(400).json({ error: error });
|
res.status(400).json({ error: error });
|
||||||
|
|
|
@ -23,10 +23,9 @@ export default async function user(req: NextApiRequest, res: NextApiResponse<Res
|
||||||
const { expiresAt } = apiInDb;
|
const { expiresAt } = apiInDb;
|
||||||
// if (!apiInDb) res.status(400).json({ error: 'Your api key is not valid' });
|
// if (!apiInDb) res.status(400).json({ error: 'Your api key is not valid' });
|
||||||
if (expiresAt && dateInPast(expiresAt, today)) {
|
if (expiresAt && dateInPast(expiresAt, today)) {
|
||||||
console.log(apiInDb)
|
|
||||||
try {
|
try {
|
||||||
const users = await prisma.user.findMany();
|
const data = await prisma.user.findMany();
|
||||||
res.status(200).json({ data: { ...users } });
|
res.status(200).json({ data });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// FIXME: Add zod for validation/error handling
|
// FIXME: Add zod for validation/error handling
|
||||||
res.status(400).json({ error: error });
|
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} });
|
// const apiKey = await prisma.apiKey.findUnique({ where: { id: req.query.id} });
|
||||||
await handleDeleteApiKey(req, res);
|
await handleDeleteApiKey(req, res);
|
||||||
|
|
||||||
// console.log(res)
|
|
||||||
expect(res._getStatusCode()).toBe(204);
|
expect(res._getStatusCode()).toBe(204);
|
||||||
expect(JSON.parse(res._getData())).toEqual({message: `api-key with id: ${apiKey?.id} deleted successfully`});
|
expect(JSON.parse(res._getData())).toEqual({message: `api-key with id: ${apiKey?.id} deleted successfully`});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue