Skip to content

Commit 6ce4122

Browse files
authored
fix: allows patching booking and period limits from API (#10935)
1 parent 7ddbcfc commit 6ce4122

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

apps/api/lib/validations/event-type.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ export const schemaEventTypeBaseBodyParams = EventType.pick({
3333
position: true,
3434
eventName: true,
3535
timeZone: true,
36+
schedulingType: true,
37+
// START Limit future bookings
3638
periodType: true,
3739
periodStartDate: true,
38-
schedulingType: true,
3940
periodEndDate: true,
4041
periodDays: true,
4142
periodCountCalendarDays: true,
43+
// END Limit future bookings
4244
requiresConfirmation: true,
4345
disableGuests: true,
4446
hideCalendarNotes: true,
@@ -51,6 +53,8 @@ export const schemaEventTypeBaseBodyParams = EventType.pick({
5153
slotInterval: true,
5254
successRedirectUrl: true,
5355
locations: true,
56+
bookingLimits: true,
57+
durationLimits: true,
5458
})
5559
.merge(z.object({ hosts: z.array(hostSchema).optional().default([]) }))
5660
.partial()
@@ -126,6 +130,8 @@ export const schemaEventTypeReadPublic = EventType.pick({
126130
seatsPerTimeSlot: true,
127131
seatsShowAttendees: true,
128132
bookingFields: true,
133+
bookingLimits: true,
134+
durationLimits: true,
129135
}).merge(
130136
z.object({
131137
locations: z

apps/api/pages/api/event-types/[id]/_patch.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Prisma } from "@prisma/client";
1+
import { Prisma } from "@prisma/client";
22
import type { NextApiRequest } from "next";
33
import type { z } from "zod";
44

@@ -202,10 +202,17 @@ import checkTeamEventEditPermission from "../_utils/checkTeamEventEditPermission
202202
export async function patchHandler(req: NextApiRequest) {
203203
const { prisma, query, body } = req;
204204
const { id } = schemaQueryIdParseInt.parse(query);
205-
const { hosts = [], ...parsedBody } = schemaEventTypeEditBodyParams.parse(body);
205+
const {
206+
hosts = [],
207+
bookingLimits,
208+
durationLimits,
209+
...parsedBody
210+
} = schemaEventTypeEditBodyParams.parse(body);
206211

207212
const data: Prisma.EventTypeUpdateArgs["data"] = {
208213
...parsedBody,
214+
bookingLimits: bookingLimits === null ? Prisma.DbNull : bookingLimits,
215+
durationLimits: durationLimits === null ? Prisma.DbNull : durationLimits,
209216
};
210217

211218
if (hosts) {

apps/api/pages/api/event-types/_post.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Prisma } from "@prisma/client";
1+
import { Prisma } from "@prisma/client";
22
import type { NextApiRequest } from "next";
33

44
import { HttpError } from "@calcom/lib/http-error";
@@ -259,12 +259,19 @@ import ensureOnlyMembersAsHosts from "./_utils/ensureOnlyMembersAsHosts";
259259
async function postHandler(req: NextApiRequest) {
260260
const { userId, isAdmin, prisma, body } = req;
261261

262-
const { hosts = [], ...parsedBody } = schemaEventTypeCreateBodyParams.parse(body || {});
262+
const {
263+
hosts = [],
264+
bookingLimits,
265+
durationLimits,
266+
...parsedBody
267+
} = schemaEventTypeCreateBodyParams.parse(body || {});
263268

264269
let data: Prisma.EventTypeCreateArgs["data"] = {
265270
...parsedBody,
266271
userId,
267272
users: { connect: { id: userId } },
273+
bookingLimits: bookingLimits === null ? Prisma.DbNull : bookingLimits,
274+
durationLimits: durationLimits === null ? Prisma.DbNull : durationLimits,
268275
};
269276

270277
await checkPermissions(req);

packages/prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ model EventType {
7979
bookingFields Json?
8080
timeZone String?
8181
periodType PeriodType @default(UNLIMITED)
82+
/// @zod.custom(imports.coerceToDate)
8283
periodStartDate DateTime?
84+
/// @zod.custom(imports.coerceToDate)
8385
periodEndDate DateTime?
8486
periodDays Int?
8587
periodCountCalendarDays Boolean?

packages/prisma/zod-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,5 @@ export const ZVerifyCodeInputSchema = z.object({
608608
});
609609

610610
export type ZVerifyCodeInputSchema = z.infer<typeof ZVerifyCodeInputSchema>;
611+
612+
export const coerceToDate = z.coerce.date();

0 commit comments

Comments
 (0)