fix: attendees move to use pick, separate patch/post

This commit is contained in:
Agusti Fernandez Pardo committed 2022-04-26 22:12:28 +02:00
1 parent bceeeebfb8
commit 3759eccfca
4 files changed
+25 -17

No files matched your search

+19 -8
View File
@@ -3,21 +3,32 @@ import { z } from "zod";
import { _AttendeeModel as Attendee } from "@calcom/prisma/zod";
export const schemaAttendeeBaseBodyParams = Attendee.omit({ id: true }).partial();
export const schemaAttendeeBaseBodyParams = Attendee.pick({
bookingId: true,
email: true,
name: true,
timeZone: true,
}).partial();
export const schemaAttendeePublic = Attendee.omit({});
const schemaAttendeeRequiredParams = z.object({
const schemaAttendeeCreateRequiredParams = z.object({
bookingId: z.any(),
email: z.string().email(),
name: z.string(),
timeZone: z.string(),
});
export const schemaAttendeeBodyParams = schemaAttendeeBaseBodyParams.merge(schemaAttendeeRequiredParams);
export const withValidAttendee = withValidation({
schema: schemaAttendeeBodyParams,
type: "Zod",
mode: "body",
const schemaAttendeeEditeRequiredParams = z.object({
// bookingId: z.any(),
// @note: disallowing email changes in attendee via API for now.
// email: z.string().email(),
name: z.string(),
timeZone: z.string(),
});
export const schemaAttendeeEditBodyParams = schemaAttendeeBaseBodyParams.merge(
schemaAttendeeEditeRequiredParams
);
export const schemaAttendeeCreateBodyParams = schemaAttendeeBaseBodyParams.merge(
schemaAttendeeCreateRequiredParams
);
+2 -5
View File
@@ -74,7 +74,7 @@ export const schemaUserBaseBodyParams = User.pick({
// Here we can both require or not (adding optional or nullish) and also rewrite validations for any value
// for example making weekStart only accept weekdays as input
const schemaUserRequiredParams = z.object({
const schemaUserEditParams = z.object({
weekStart: z.nativeEnum(weekdays).optional(),
brandColor: z.string().min(4).max(9).regex(/^#/).optional(),
timeZone: z
@@ -96,7 +96,7 @@ const schemaUserRequiredParams = z.object({
// @note: These are the values that are editable via PATCH method on the user Model,
// merging both BaseBodyParams with RequiredParams, and omiting whatever we want at the end.
export const schemaUserEditBodyParams = schemaUserBaseBodyParams.merge(schemaUserRequiredParams).omit({});
export const schemaUserEditBodyParams = schemaUserBaseBodyParams.merge(schemaUserEditParams).omit({});
// @note: These are the values that are always returned when reading a user
export const schemaUserReadPublic = User.pick({
@@ -123,6 +123,3 @@ export const schemaUserReadPublic = User.pick({
verified: true,
invitedTo: true,
});
// @note: This is the validation for the PATCH method on the user Model. Not used for now.
export const withValidUser = withValidation({ schema: schemaUserEditBodyParams, type: "Zod", mode: "body" });