* feat: Add upcoming bookings feature to GET /api/bookings endpoint - Added support for filtering upcoming bookings by adding the `upcoming` query parameter to the GET /api/bookings endpoint. - When `upcoming` is set to "true", only upcoming bookings are returned. - Regular users can now retrieve only their upcoming bookings by setting `upcoming` to "true". - System-wide admins and organization admins can also retrieve only upcoming bookings by setting `upcoming` to "true". * feat: Add status filter to booking API endpoint This commit adds a new `status` filter to the booking API endpoint. The `status` filter allows filtering bookings by their status, overriding the `dateFrom` and `dateTo` filters. The only valid value for the `status` filter is "upcoming". * Update _get.ts --------- Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
92 lines
2.1 KiB
TypeScript
92 lines
2.1 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { _AttendeeModel, _BookingModel as Booking, _PaymentModel, _UserModel } from "@calcom/prisma/zod";
|
|
import { extendedBookingCreateBody, iso8601 } from "@calcom/prisma/zod-utils";
|
|
|
|
import { schemaQueryUserId } from "./shared/queryUserId";
|
|
|
|
const schemaBookingBaseBodyParams = Booking.pick({
|
|
uid: true,
|
|
userId: true,
|
|
eventTypeId: true,
|
|
title: true,
|
|
description: true,
|
|
startTime: true,
|
|
endTime: true,
|
|
status: true,
|
|
}).partial();
|
|
|
|
export const schemaBookingCreateBodyParams = extendedBookingCreateBody.merge(schemaQueryUserId.partial());
|
|
|
|
export const schemaBookingGetParams = z.object({
|
|
dateFrom: iso8601.optional(),
|
|
dateTo: iso8601.optional(),
|
|
order: z.enum(["asc", "desc"]).default("asc"),
|
|
sortBy: z.enum(["createdAt", "updatedAt"]).optional(),
|
|
status: z.enum(["upcoming"]).optional(),
|
|
});
|
|
|
|
export type Status = z.infer<typeof schemaBookingGetParams>["status"];
|
|
|
|
const schemaBookingEditParams = z
|
|
.object({
|
|
title: z.string().optional(),
|
|
startTime: iso8601.optional(),
|
|
endTime: iso8601.optional(),
|
|
// Not supporting responses in edit as that might require re-triggering emails
|
|
// responses
|
|
})
|
|
.strict();
|
|
|
|
export const schemaBookingEditBodyParams = schemaBookingBaseBodyParams
|
|
.merge(schemaBookingEditParams)
|
|
.omit({ uid: true });
|
|
|
|
export const schemaBookingReadPublic = Booking.extend({
|
|
attendees: z
|
|
.array(
|
|
_AttendeeModel.pick({
|
|
email: true,
|
|
name: true,
|
|
timeZone: true,
|
|
locale: true,
|
|
})
|
|
)
|
|
.optional(),
|
|
user: _UserModel
|
|
.pick({
|
|
email: true,
|
|
name: true,
|
|
timeZone: true,
|
|
locale: true,
|
|
})
|
|
.nullish(),
|
|
payment: z
|
|
.array(
|
|
_PaymentModel.pick({
|
|
id: true,
|
|
success: true,
|
|
paymentOption: true,
|
|
})
|
|
)
|
|
.optional(),
|
|
responses: z.record(z.any()).nullable(),
|
|
}).pick({
|
|
id: true,
|
|
userId: true,
|
|
description: true,
|
|
eventTypeId: true,
|
|
uid: true,
|
|
title: true,
|
|
startTime: true,
|
|
endTime: true,
|
|
timeZone: true,
|
|
attendees: true,
|
|
user: true,
|
|
payment: true,
|
|
metadata: true,
|
|
status: true,
|
|
responses: true,
|
|
fromReschedule: true,
|
|
});
|