Merge pull request #78 from calcom/fix/meta

Fix/meta
pull/9078/head
Agusti Fernandez Pardo 2022-05-18 15:29:42 +02:00 committed by GitHub
commit a7889b3436
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 60 additions and 17 deletions

View File

@ -32,19 +32,20 @@ export const schemaEventTypeBaseBodyParams = EventType.pick({
successRedirectUrl: true,
}).partial();
const schemaEventTypeBaseParams = z
const schemaEventTypeCreateParams = z
.object({
title: z.string(),
slug: z.string(),
description: z.string().optional().nullable(),
length: z.number().int(),
locations: jsonSchema.optional().nullable().or(z.null()),
metadata: jsonSchema.optional().nullish(),
metadata: z.any().optional().nullable().nullish(),
recurringEvent: jsonSchema.optional().nullable().or(z.null()),
})
.strict();
export const schemaEventTypeCreateBodyParams = schemaEventTypeBaseBodyParams.merge(schemaEventTypeBaseParams);
export const schemaEventTypeCreateBodyParams =
schemaEventTypeBaseBodyParams.merge(schemaEventTypeCreateParams);
const schemaEventTypeEditParams = z
.object({
@ -84,6 +85,12 @@ export const schemaEventTypeReadPublic = EventType.pick({
currency: true,
slotInterval: true,
successRedirectUrl: true,
description: true,
})
.merge(schemaEventTypeBaseParams)
.partial();
.merge(
z.object({
recurringEvent: jsonSchema.nullable(),
metadata: jsonSchema.nullable(),
})
)
.strict();

View File

@ -18,7 +18,10 @@ export async function bookingReferenceById(
res: NextApiResponse<BookingReferenceResponse>
) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
// const userWithBookings = await prisma.user.findUnique({
// where: { id: userId },
// include: { bookings: true },

View File

@ -15,7 +15,10 @@ export async function bookingById(
res: NextApiResponse<BookingResponse>
) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
include: { bookings: true },

View File

@ -77,7 +77,10 @@ async function eventTypeById(
) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaEventTypeCustomInputBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
const data = await prisma.eventType.findMany({ where: { userId } });
const userEventTypes = data.map((eventType) => eventType.id);
const userEventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany({

View File

@ -19,7 +19,10 @@ export async function destionationCalendarById(
) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaDestinationCalendarEditBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
const data = await prisma.destinationCalendar.findMany({ where: { userId } });
const userDestinationCalendars = data.map((destinationCalendar) => destinationCalendar.id);
// FIXME: Should we also check ownership of bokingId and eventTypeId to avoid users cross-pollinating other users calendars.

View File

@ -19,7 +19,10 @@ export async function dailyEventReferenceById(
) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaDailyEventReferenceEditBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
const userBookings = await prisma.booking.findMany({ where: { userId } });
const userBookingIds: number[] = userBookings.map((booking) => booking.id);
const userBookingDailyEventReferences = await prisma.dailyEventReference.findMany({

View File

@ -15,7 +15,10 @@ export async function eventTypeById(
res: NextApiResponse<EventTypeResponse>
) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
const data = await prisma.eventType.findMany({ where: { userId } });
const userEventTypes = data.map((eventType) => eventType.id);
if (!userEventTypes.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });

View File

@ -12,7 +12,10 @@ export async function WebhookById(
res: NextApiResponse<WebhookResponse>
) {
const safeQuery = schemaQueryIdAsString.safeParse(query);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
const data = await prisma.webhook.findMany({ where: { userId } });
const userWebhooks = data.map((webhook) => webhook.id);
if (!userWebhooks.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });

View File

@ -12,7 +12,10 @@ export async function membershipById(
res: NextApiResponse<MembershipResponse>
) {
const safeQuery = schemaQueryIdAsString.safeParse(query);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
// This is how we set the userId and teamId in the query for managing compoundId.
const [paramUserId, teamId] = safeQuery.data.id.split("_");
if (parseInt(paramUserId) !== userId) res.status(401).json({ message: "Unauthorized" });

View File

@ -16,7 +16,10 @@ export async function scheduleById(
) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaScheduleBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
const userSchedules = await prisma.schedule.findMany({ where: { userId } });
const userScheduleIds = userSchedules.map((schedule) => schedule.id);
if (!userScheduleIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });

View File

@ -16,7 +16,10 @@ export async function selectedCalendarById(
) {
const safeQuery = schemaQueryIdAsString.safeParse(query);
const safeBody = schemaSelectedCalendarBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
// This is how we set the userId and externalId in the query for managing compoundId.
const [paramUserId, integration, externalId] = safeQuery.data.id.split("_");
if (userId !== parseInt(paramUserId)) res.status(401).json({ message: "Unauthorized" });

View File

@ -77,7 +77,10 @@ export async function teamById(
) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaTeamBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
const userWithMemberships = await prisma.membership.findMany({
where: { userId: userId },
});

View File

@ -16,7 +16,10 @@ export async function userById(
) {
const safeQuery = schemaQueryIdParseInt.safeParse(query);
console.log(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
if (!safeQuery.success) {
res.status(400).json({ message: "Your query was invalid" });
return;
}
if (safeQuery.data.id !== userId) res.status(401).json({ message: "Unauthorized" });
else {
switch (method) {