Skip to content

Commit

Permalink
feat: add get event types by mentor
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew4Coding committed Sep 4, 2024
1 parent c3ca0bb commit a783579
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions apps/web/pages/api/eventtype/mentor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { NextApiRequest, NextApiResponse } from "next/types";
import { z } from "zod";

import prisma from "@calcom/prisma";

export const getEventTypeQuerySchema = z.object({
userEmail: z.string().optional(),
page: z
.preprocess((val) => Number(val), z.number().int().positive())
.optional()
.default(1),
take: z
.preprocess((val) => Number(val), z.number().int().positive())
.optional()
.default(10),
});

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
const { userEmail, page, take } = getEventTypeQuerySchema.parse(req.query);

const eventTypes = await prisma.user.findMany({
where: {
email: userEmail,
},
take: take,
skip: (page - 1) * take,
include: {
eventTypes: true,
},
});

const mappedEventTypes = eventTypes.map((item) => {
return {
userId: item.id,
userEmail: item.email,
eventTypes: item.eventTypes,
page: page,
take: take,
};
});
return mappedEventTypes;
} catch (error) {
return error;
}
}

0 comments on commit a783579

Please sign in to comment.