Files
calendar/apps/api/v1/lib/validations/booking.ts
T
b6d31129a3 feat: Add rescheduledBy & canceledBy fields in the DB (#15337)
* feat: Add rescheduledBy & canceledBy fields in the DB

* fix: type check

* fix: type check

* fix: use session user email for reschedule

* fix: unit test

* feat: db field email validation

* feat: rescheduledBy and cancelledBy in webhooks

* revert unrelated changes.

* make session user secondary, default to Anonymous

* if condition not required

* Make cancelledBy optional

Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>

* update cancel booking type

* fix: update cancelledBy in db when requesting reschedule

* remove default value for fields

* fix: type check

* feat: manage fields via api v1

* fix: add fields in booking read api v1

* test: expand to cover new fields

* fix: use cancelledBy param on booking page

---------

Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
2024-08-25 11:31:46 +02:00

98 lines
2.4 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,
rescheduledBy: true,
cancelledBy: 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(),
cancelledBy: z.string().email({ message: "Invalid Email" }).optional(),
rescheduledBy: z.string().email({ message: "Invalid Email" }).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,
cancelledBy: true,
rescheduledBy: true,
});