Fix: add strict and optional to have errors on extraneus params

pull/9078/head
Agusti Fernandez Pardo 2022-04-27 19:45:59 +02:00
parent e52af0bbef
commit 238b03791e
6 changed files with 94 additions and 73 deletions

View File

@ -15,14 +15,13 @@ const schemaAttendeeCreateParams = z
.object({
bookingId: z.number().int(),
email: z.string().email(),
name: z.string(),
name: z.string().optional(),
timeZone: timeZone,
})
.strict();
const schemaAttendeeEditParams = z
.object({
// @note: disallowing bookingId changes in attendee via API for now as it would introduce side effects
name: z.string().optional(),
email: z.string().email().optional(),
timeZone: timeZone.optional(),

View File

@ -21,19 +21,24 @@ export const schemaAvailabilityReadPublic = Availability.pick({
eventTypeId: true,
});
const schemaAvailabilityCreateParams = z.object({
startTime: z.date().or(z.string()),
endTime: z.date().or(z.string()),
days: z.array(z.number()).optional(),
eventTypeId: z.number().optional(),
});
const schemaAvailabilityCreateParams = z
.object({
startTime: z.date().or(z.string()),
endTime: z.date().or(z.string()),
days: z.array(z.number()).optional(),
eventTypeId: z.number().optional(),
})
.strict();
const schemaAvailabilityEditParams = z
.object({
startTime: z.date().or(z.string()).optional(),
endTime: z.date().or(z.string()).optional(),
days: z.array(z.number()).optional(),
eventTypeId: z.number().optional(),
})
.strict();
const schemaAvailabilityEditParams = z.object({
startTime: z.date().or(z.string()).optional(),
endTime: z.date().or(z.string()).optional(),
days: z.array(z.number()).optional(),
eventTypeId: z.number().optional(),
});
export const schemaAvailabilityEditBodyParams = schemaAvailabilityBaseBodyParams.merge(
schemaAvailabilityEditParams
);

View File

@ -23,22 +23,28 @@ export const schemaBookingReferenceReadPublic = BookingReference.pick({
deleted: true,
});
const schemaBookingReferenceEditParams = z.object({
type: z.string(),
uid: z.string(),
meetingId: z.string(),
meetingPassword: z.string(),
meetingUrl: z.string(),
deleted: z.boolean(),
});
const schemaBookingReferenceCreateParams = z.object({
type: z.string(),
uid: z.string(),
meetingId: z.string(),
meetingPassword: z.string(),
meetingUrl: z.string(),
deleted: z.boolean(),
});
const schemaBookingReferenceCreateParams = z
.object({
type: z.string(),
uid: z.string(),
meetingId: z.string(),
meetingPassword: z.string(),
meetingUrl: z.string(),
deleted: z.boolean(),
})
.strict();
const schemaBookingReferenceEditParams = z
.object({
type: z.string().optional(),
uid: z.string().optional(),
meetingId: z.string().optional(),
meetingPassword: z.string().optional(),
meetingUrl: z.string().optional(),
deleted: z.boolean().optional(),
})
.strict();
export const schemaBookingCreateBodyParams = schemaBookingReferenceBaseBodyParams.merge(
schemaBookingReferenceCreateParams
);

View File

@ -11,24 +11,27 @@ const schemaBookingBaseBodyParams = Booking.pick({
endTime: true,
}).partial();
const schemaBookingCreateParams = z.object({
uid: z.string(),
userId: z.number(),
eventTypeId: z.number(),
title: z.string(),
startTime: z.date(),
endTime: z.date(),
});
const schemaBookingCreateParams = z
.object({
uid: z.string(),
userId: z.number(),
eventTypeId: z.number(),
title: z.string(),
startTime: z.date(),
endTime: z.date(),
})
.strict();
export const schemaBookingCreateBodyParams = schemaBookingBaseBodyParams.merge(schemaBookingCreateParams);
// @note: disallowing userId/eventTypeId changes in booking endpoint via PATCH for now as it would introduce side effects
const schemaBookingEditParams = z.object({
uid: z.string(),
title: z.string(),
startTime: z.date(),
endTime: z.date(),
});
const schemaBookingEditParams = z
.object({
uid: z.string().optional(),
title: z.string().optional(),
startTime: z.date().optional(),
endTime: z.date().optional(),
})
.strict();
export const schemaBookingEditBodyParams = schemaBookingBaseBodyParams.merge(schemaBookingEditParams);

View File

@ -8,21 +8,24 @@ export const schemaDailyEventReferenceBaseBodyParams = DailyEventReference.pick(
bookingId: true,
}).partial();
const schemaDailyEventReferenceCreateParams = z.object({
dailytoken: z.string(),
dailyurl: z.string(),
bookingId: z.number(),
});
const schemaDailyEventReferenceCreateParams = z
.object({
dailytoken: z.string(),
dailyurl: z.string(),
bookingId: z.number(),
})
.strict();
export const schemaDailyEventReferenceCreateBodyParams = schemaDailyEventReferenceBaseBodyParams.merge(
schemaDailyEventReferenceCreateParams
);
const schemaDailyEventReferenceEditParams = z.object({
dailytoken: z.string(),
dailyurl: z.string(),
// @note: disallowing bookingId changes in daily-event-reference via API endpoint for now as it would introduce side effects
});
const schemaDailyEventReferenceEditParams = z
.object({
dailytoken: z.string().optional(),
dailyurl: z.string().optional(),
})
.strict();
export const schemaDailyEventReferenceEditBodyParams = schemaDailyEventReferenceBaseBodyParams.merge(
schemaDailyEventReferenceEditParams

View File

@ -10,29 +10,34 @@ export const schemaDestinationCalendarBaseBodyParams = DestinationCalendar.pick(
userId: true,
}).partial();
const schemaDestinationCalendarEditParams = z.object({
integration: z.string(),
externalId: z.string(),
eventTypeId: z.number(),
bookingId: z.number(),
userId: z.number(),
});
export const schemaDestinationCalendarEditBodyParams = schemaDestinationCalendarBaseBodyParams.merge(
schemaDestinationCalendarEditParams
);
const schemaDestinationCalendarCreateParams = z.object({
integration: z.string(),
externalId: z.string(),
eventTypeId: z.number(),
bookingId: z.number(),
userId: z.number(),
});
const schemaDestinationCalendarCreateParams = z
.object({
integration: z.string(),
externalId: z.string(),
eventTypeId: z.number(),
bookingId: z.number(),
userId: z.number(),
})
.strict();
export const schemaDestinationCalendarCreateBodyParams = schemaDestinationCalendarBaseBodyParams.merge(
schemaDestinationCalendarCreateParams
);
const schemaDestinationCalendarEditParams = z
.object({
integration: z.string().optional(),
externalId: z.string().optional(),
eventTypeId: z.number().optional(),
bookingId: z.number().optional(),
userId: z.number().optional(),
})
.strict();
export const schemaDestinationCalendarEditBodyParams = schemaDestinationCalendarBaseBodyParams.merge(
schemaDestinationCalendarEditParams
);
export const schemaDestinationCalendarReadPublic = DestinationCalendar.pick({
id: true,
integration: true,