Set reqBody.end to start + eventType.length (#9296)
This commit is contained in:
1 parent
f7ce774ddc
commit
7fc0877c26
2 files changed
+37
-10
No files matched your search
@@ -468,6 +468,13 @@ function getBookingData({
|
|||||||
if (val.responses) {
|
if (val.responses) {
|
||||||
const unwantedProps: string[] = [];
|
const unwantedProps: string[] = [];
|
||||||
legacyProps.forEach((legacyProp) => {
|
legacyProps.forEach((legacyProp) => {
|
||||||
|
if (typeof val[legacyProp as keyof typeof val] !== "undefined") {
|
||||||
|
console.error(
|
||||||
|
`Deprecated: Unexpected falsy value for: ${unwantedProps.join(
|
||||||
|
","
|
||||||
|
)}. They can't be used with \`responses\`. This will become a 400 error in the future.`
|
||||||
|
);
|
||||||
|
}
|
||||||
if (val[legacyProp as keyof typeof val]) {
|
if (val[legacyProp as keyof typeof val]) {
|
||||||
unwantedProps.push(legacyProp);
|
unwantedProps.push(legacyProp);
|
||||||
}
|
}
|
||||||
@@ -489,7 +496,24 @@ function getBookingData({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const reqBody = bookingDataSchema.parse(req.body);
|
const reqBody = bookingDataSchema.parse(req.body);
|
||||||
|
|
||||||
|
// Work with Typescript to require reqBody.end
|
||||||
|
type ReqBodyWithoutEnd = z.infer<typeof bookingDataSchema>;
|
||||||
|
type ReqBodyWithEnd = ReqBodyWithoutEnd & { end: string };
|
||||||
|
|
||||||
|
const reqBodyWithEnd = (reqBody: ReqBodyWithoutEnd): reqBody is ReqBodyWithEnd => {
|
||||||
|
// Use the event length to auto-set the event end time.
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(reqBody, "end")) {
|
||||||
|
reqBody.end = dayjs.utc(reqBody.start).add(eventType.length, "minutes").format();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
if (!reqBodyWithEnd(reqBody)) {
|
||||||
|
throw new Error("Internal Error.");
|
||||||
|
}
|
||||||
|
// reqBody.end is no longer an optional property.
|
||||||
if ("customInputs" in reqBody) {
|
if ("customInputs" in reqBody) {
|
||||||
if (reqBody.customInputs) {
|
if (reqBody.customInputs) {
|
||||||
// Check if required custom inputs exist
|
// Check if required custom inputs exist
|
||||||
@@ -667,7 +691,7 @@ async function handler(
|
|||||||
metadata: true,
|
metadata: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
: !!eventType.hosts?.length
|
: eventType.hosts?.length
|
||||||
? eventType.hosts.map(({ user, isFixed }) => ({
|
? eventType.hosts.map(({ user, isFixed }) => ({
|
||||||
...user,
|
...user,
|
||||||
isFixed,
|
isFixed,
|
||||||
@@ -731,14 +755,17 @@ async function handler(
|
|||||||
defaultLocationUrl = firstUsersMetadata?.defaultConferencingApp?.appLink;
|
defaultLocationUrl = firstUsersMetadata?.defaultConferencingApp?.appLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventType && eventType.hasOwnProperty("bookingLimits") && eventType?.bookingLimits) {
|
if (
|
||||||
|
Object.prototype.hasOwnProperty.call(eventType, "bookingLimits") ||
|
||||||
|
Object.prototype.hasOwnProperty.call(eventType, "durationLimits")
|
||||||
|
) {
|
||||||
const startAsDate = dayjs(reqBody.start).toDate();
|
const startAsDate = dayjs(reqBody.start).toDate();
|
||||||
await checkBookingLimits(eventType.bookingLimits, startAsDate, eventType.id);
|
if (eventType.bookingLimits) {
|
||||||
}
|
await checkBookingLimits(eventType.bookingLimits, startAsDate, eventType.id);
|
||||||
|
}
|
||||||
if (eventType && eventType.hasOwnProperty("durationLimits") && eventType?.durationLimits) {
|
if (eventType.durationLimits) {
|
||||||
const startAsDate = dayjs(reqBody.start).toDate();
|
await checkDurationLimits(eventType.durationLimits, startAsDate, eventType.id);
|
||||||
await checkDurationLimits(eventType.durationLimits, startAsDate, eventType.id);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!eventType.seatsPerTimeSlot) {
|
if (!eventType.seatsPerTimeSlot) {
|
||||||
@@ -911,7 +938,7 @@ async function handler(
|
|||||||
requiresConfirmation: requiresConfirmation ?? false,
|
requiresConfirmation: requiresConfirmation ?? false,
|
||||||
eventTypeId: eventType.id,
|
eventTypeId: eventType.id,
|
||||||
// if seats are not enabled we should default true
|
// if seats are not enabled we should default true
|
||||||
seatsShowAttendees: !!eventType.seatsPerTimeSlot ? eventType.seatsShowAttendees : true,
|
seatsShowAttendees: eventType.seatsPerTimeSlot ? eventType.seatsShowAttendees : true,
|
||||||
seatsPerTimeSlot: eventType.seatsPerTimeSlot,
|
seatsPerTimeSlot: eventType.seatsPerTimeSlot,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ export const stringOrNumber = z.union([
|
|||||||
export const stringToDayjs = z.string().transform((val) => dayjs(val));
|
export const stringToDayjs = z.string().transform((val) => dayjs(val));
|
||||||
|
|
||||||
export const bookingCreateBodySchema = z.object({
|
export const bookingCreateBodySchema = z.object({
|
||||||
end: z.string(),
|
end: z.string().optional(),
|
||||||
eventTypeId: z.number(),
|
eventTypeId: z.number(),
|
||||||
eventTypeSlug: z.string().optional(),
|
eventTypeSlug: z.string().optional(),
|
||||||
rescheduleUid: z.string().optional(),
|
rescheduleUid: z.string().optional(),
|
||||||
|
|||||||
Reference in new issue
Block a user