fix users, availabilites, attendees
This commit is contained in:
1 parent
096fd40044
commit
dad70d5a12
7 files changed
+93
-43
No files matched your search
@@ -3,13 +3,14 @@ import { z } from "zod";
|
||||
|
||||
import { _AvailabilityModel as Availability } from "@calcom/prisma/zod";
|
||||
|
||||
export const schemaAvailabilityBaseBodyParams = Availability.omit({ id: true }).partial();
|
||||
export const schemaAvailabilityBaseBodyParams = Availability.pick({ userId: true, eventTypeId: true, days: true }).partial();
|
||||
|
||||
export const schemaAvailabilityPublic = Availability.omit({});
|
||||
|
||||
const schemaAvailabilityRequiredParams = z.object({
|
||||
startTime: z.string(),
|
||||
endTime: z.string(),
|
||||
startTime: z.date().or(z.string()).optional(),
|
||||
endTime: z.date().or(z.string()).optional(),
|
||||
days: z.any().optional(),
|
||||
});
|
||||
|
||||
export const schemaAvailabilityBodyParams = schemaAvailabilityBaseBodyParams.merge(
|
||||
|
||||
+61
-23
@@ -3,34 +3,72 @@ import { z } from "zod";
|
||||
|
||||
import { _UserModel as User } from "@calcom/prisma/zod";
|
||||
|
||||
export const schemaUserBaseBodyParams = User.omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
password: true,
|
||||
twoFactorEnabled: true,
|
||||
twoFactorSecret: true,
|
||||
// @note: These are the ONLY values allowed as weekStart. So user don't introduce bad data.
|
||||
enum weekdays {
|
||||
MONDAY = "Monday",
|
||||
TUESDAY = "Tuesday",
|
||||
WEDNESDAY = "Wednesday",
|
||||
THURSDAY = "Thursday",
|
||||
FRIDAY = "Friday",
|
||||
SATURDAY = "Saturday",
|
||||
SUNDAY = "Sunday",
|
||||
}
|
||||
|
||||
// @note: These are the values that are editable via PATCH method on the user Model
|
||||
export const schemaUserBaseBodyParams = User.pick({
|
||||
name: true,
|
||||
bio: true,
|
||||
avatar: true,
|
||||
timeZone: true,
|
||||
weekStart: true,
|
||||
endTime: true,
|
||||
bufferTime: true,
|
||||
theme: true,
|
||||
defaultScheduleId: true,
|
||||
locale: true,
|
||||
timeFormat: true,
|
||||
brandColor: true,
|
||||
darkBrandColor: true,
|
||||
allowDynamicBooking: true,
|
||||
away: true,
|
||||
}).partial();
|
||||
// @note: partial() is used to allow for the user to edit only the fields they want to edit making all optional,
|
||||
// if want to make any required do it in the schemaRequiredParams
|
||||
|
||||
// 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({
|
||||
email: z.string().email(),
|
||||
weekStart: z.nativeEnum(weekdays).optional(),
|
||||
});
|
||||
|
||||
export const schemaUserBodyParams = schemaUserBaseBodyParams.merge(schemaUserRequiredParams);
|
||||
// @note: These are the values that are editable via PATCH method on the user Model
|
||||
export const schemaUserEditBodyParams = schemaUserBaseBodyParams.merge(schemaUserRequiredParams).omit({});
|
||||
|
||||
export const schemaUserPublic = User.omit({
|
||||
identityProvider: true,
|
||||
identityProviderId: true,
|
||||
plan: true,
|
||||
metadata: true,
|
||||
password: true,
|
||||
twoFactorEnabled: true,
|
||||
twoFactorSecret: true,
|
||||
trialEndsAt: true,
|
||||
completedOnboarding: true,
|
||||
// @note: These are the values that are always returned when reading a user
|
||||
export const schemaUserReadPublic = User.pick({
|
||||
id: true,
|
||||
username: true,
|
||||
name: true,
|
||||
email: true,
|
||||
emailVerified: true,
|
||||
bio: true,
|
||||
avatar: true,
|
||||
timeZone: true,
|
||||
weekStart: true,
|
||||
endTime: true,
|
||||
bufferTime: true,
|
||||
theme: true,
|
||||
defaultScheduleId: true,
|
||||
locale: true,
|
||||
timeFormat: true,
|
||||
brandColor: true,
|
||||
darkBrandColor: true,
|
||||
allowDynamicBooking: true,
|
||||
away: true,
|
||||
createdDate: true,
|
||||
verified: true,
|
||||
invitedTo: true,
|
||||
});
|
||||
|
||||
export const withValidUser = withValidation({
|
||||
schema: schemaUserBodyParams,
|
||||
type: "Zod",
|
||||
mode: "body",
|
||||
});
|
||||
// @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" });
|
||||
Reference in new issue
Block a user