feat: inherit all validations from auto-generated zod

This commit is contained in:
Agusti Fernandez Pardo committed 2022-03-30 17:37:51 +02:00
1 parent 064c39b7f6
commit 9aa4b0e30d
19 files changed
+372 -224

No files matched your search

+115 -3
View File
@@ -1,4 +1,20 @@
import { User, ApiKey, Team, SelectedCalendar } from "@calcom/prisma/client";
import {
User,
ApiKey,
Team,
SelectedCalendar,
EventType,
Attendee,
Availability,
BookingReference,
Booking,
DailyEventReference,
Webhook,
DestinationCalendar,
Membership,
Payment,
Schedule,
} from "@calcom/prisma/client";
// Base response, used for all responses
export type BaseResponse = {
@@ -21,7 +37,7 @@ export type ApiKeysResponse = BaseResponse & {
data?: Partial<ApiKey>[];
};
// API Key
// Team
export type TeamResponse = BaseResponse & {
data?: Partial<Team>;
};
@@ -29,10 +45,106 @@ export type TeamsResponse = BaseResponse & {
data?: Partial<Team>[];
};
// API Key
// SelectedCalendar
export type SelectedCalendarResponse = BaseResponse & {
data?: Partial<SelectedCalendar>;
};
export type SelectedCalendarsResponse = BaseResponse & {
data?: Partial<SelectedCalendar>[];
};
// Attendee
export type AttendeeResponse = BaseResponse & {
data?: Partial<Attendee>;
};
export type AttendeesResponse = BaseResponse & {
data?: Partial<Attendee>[];
};
// Availability
export type AvailabilityResponse = BaseResponse & {
data?: Partial<Availability>;
};
export type AvailabilitysResponse = BaseResponse & {
data?: Partial<Availability>[];
};
// BookingReference
export type BookingReferenceResponse = BaseResponse & {
data?: Partial<BookingReference>;
};
export type BookingReferencesResponse = BaseResponse & {
data?: Partial<BookingReference>[];
};
// Booking
export type BookingResponse = BaseResponse & {
data?: Partial<Booking>;
};
export type BookingsResponse = BaseResponse & {
data?: Partial<Booking>[];
};
// Credential
export type CredentialResponse = BaseResponse & {
data?: Partial<Credential>;
};
export type CredentialsResponse = BaseResponse & {
data?: Partial<Credential>[];
};
// DailyEventReference
export type DailyEventReferenceResponse = BaseResponse & {
data?: Partial<DailyEventReference>;
};
export type DailyEventReferencesResponse = BaseResponse & {
data?: Partial<DailyEventReference>[];
};
// DestinationCalendar
export type DestinationCalendarResponse = BaseResponse & {
data?: Partial<DestinationCalendar>;
};
export type DestinationCalendarsResponse = BaseResponse & {
data?: Partial<DestinationCalendar>[];
};
// Membership
export type MembershipResponse = BaseResponse & {
data?: Partial<Membership>;
};
export type MembershipsResponse = BaseResponse & {
data?: Partial<Membership>[];
};
// EventType
export type EventTypeResponse = BaseResponse & {
data?: Partial<EventType>;
};
export type EventTypesResponse = BaseResponse & {
data?: Partial<EventType>[];
};
// Payment
export type PaymentResponse = BaseResponse & {
data?: Partial<Payment>;
};
export type PaymentsResponse = BaseResponse & {
data?: Partial<Payment>[];
};
// Schedule
export type ScheduleResponse = BaseResponse & {
data?: Partial<Schedule>;
};
export type SchedulesResponse = BaseResponse & {
data?: Partial<Schedule>[];
};
// Webhook
export type WebhookResponse = BaseResponse & {
data?: Partial<Webhook>;
};
export type WebhooksResponse = BaseResponse & {
data?: Partial<Webhook>[];
};
+8 -15
View File
@@ -1,20 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaAttendee = z
.object({
id: z.number(),
email: z.string().min(3),
name: z.string().min(3).email(),
timeZone: z.string().default("Europe/London"),
locale: z.string().optional(),
bookingId: z.number(),
})
.strict();
const withValidAttendee = withValidation({
schema: schemaAttendee,
import { _AttendeeModel as Attendee } from "@calcom/prisma/zod";
export const schemaAttendeeBodyParams = Attendee.omit({ id: true });
export const schemaAttendeePublic = Attendee.omit({});
export const withValidAttendee = withValidation({
schema: schemaAttendeeBodyParams,
type: "Zod",
mode: "body",
});
export { schemaAttendee, withValidAttendee };
+7 -17
View File
@@ -1,23 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaAvailability = z
.object({
id: z.number(),
userId: z.number(),
eventTypeId: z.number(),
scheduleId: z.number(),
import { _AvailabilityModel as Availability } from "@calcom/prisma/zod";
days: z.array(z.number()),
date: z.date().or(z.string()),
startTime: z.string(),
endTime: z.string(),
})
.strict();
const withValidAvailability = withValidation({
schema: schemaAvailability,
export const schemaAvailabilityBodyParams = Availability.omit({ id: true });
export const schemaAvailabilityPublic = Availability.omit({});
export const withValidAvailability = withValidation({
schema: schemaAvailabilityBodyParams,
type: "Zod",
mode: "body",
});
export { schemaAvailability, withValidAvailability };
+8 -6
View File
@@ -1,11 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaBookingReference = z.object({}).strict();
const withValidBookingReference = withValidation({
schema: schemaBookingReference,
import { _BookingReferenceModel as BookingReference } from "@calcom/prisma/zod";
export const schemaBookingReferenceBodyParams = BookingReference.omit({ id: true });
export const schemaBookingReferencePublic = BookingReference.omit({});
export const withValidBookingReference = withValidation({
schema: schemaBookingReferenceBodyParams,
type: "Zod",
mode: "body",
});
export { schemaBookingReference, withValidBookingReference };
+8 -20
View File
@@ -1,25 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaBooking = z
.object({
uid: z.string().min(3),
title: z.string().min(3),
description: z.string().min(3).optional(),
startTime: z.date().or(z.string()),
endTime: z.date(),
location: z.string().min(3).optional(),
createdAt: z.date().or(z.string()),
updatedAt: z.date().or(z.string()),
confirmed: z.boolean().default(true),
rejected: z.boolean().default(false),
paid: z.boolean().default(false),
})
.strict();
const withValidBooking = withValidation({
schema: schemaBooking,
import { _BookingModel as Booking } from "@calcom/prisma/zod";
export const schemaBookingBodyParams = Booking.omit({ id: true });
export const schemaBookingPublic = Booking.omit({});
export const withValidBooking = withValidation({
schema: schemaBookingBodyParams,
type: "Zod",
mode: "body",
});
export { schemaBooking, withValidBooking };
+8 -6
View File
@@ -1,11 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaCredential = z.object({}).strict();
const withValidCredential = withValidation({
schema: schemaCredential,
import { _CredentialModel as Credential } from "@calcom/prisma/zod";
export const schemaCredentialBodyParams = Credential.omit({ id: true });
export const schemaCredentialPublic = Credential.omit({});
export const withValidCredential = withValidation({
schema: schemaCredentialBodyParams,
type: "Zod",
mode: "body",
});
export { schemaCredential, withValidCredential };
+8 -6
View File
@@ -1,11 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaDailyEventReference = z.object({}).strict();
const withValidDailyEventReference = withValidation({
schema: schemaDailyEventReference,
import { _DailyEventReferenceModel as DailyEventReference } from "@calcom/prisma/zod";
export const schemaDailyEventReferenceBodyParams = DailyEventReference.omit({ id: true });
export const schemaDailyEventReferencePublic = DailyEventReference.omit({});
export const withValidDailyEventReference = withValidation({
schema: schemaDailyEventReferenceBodyParams,
type: "Zod",
mode: "body",
});
export { schemaDailyEventReference, withValidDailyEventReference };
+8 -6
View File
@@ -1,11 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaDestinationCalendar = z.object({}).strict();
const withValidDestinationCalendar = withValidation({
schema: schemaDestinationCalendar,
import { _DestinationCalendarModel as DestinationCalendar } from "@calcom/prisma/zod";
export const schemaDestinationCalendarBodyParams = DestinationCalendar.omit({ id: true });
export const schemaDestinationCalendarPublic = DestinationCalendar.omit({});
export const withValidDestinationCalendar = withValidation({
schema: schemaDestinationCalendarBodyParams,
type: "Zod",
mode: "body",
});
export { schemaDestinationCalendar, withValidDestinationCalendar };
+8 -13
View File
@@ -1,18 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaEventType = z
.object({
title: z.string().min(3),
slug: z.string().min(3),
length: z.number().min(1).max(1440), // max is a full day.
description: z.string().min(3).optional(),
})
.strict();
const withValidEventType = withValidation({
schema: schemaEventType,
import { _EventTypeModel as EventType } from "@calcom/prisma/zod";
export const schemaEventTypeBodyParams = EventType.omit({ id: true });
export const schemaEventTypePublic = EventType.omit({});
export const withValidEventType = withValidation({
schema: schemaEventTypeBodyParams,
type: "Zod",
mode: "body",
});
export { schemaEventType, withValidEventType };
+8 -6
View File
@@ -1,11 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaMembership = z.object({}).strict();
const withValidMembership = withValidation({
schema: schemaMembership,
import { _MembershipModel as Membership } from "@calcom/prisma/zod";
export const schemaMembershipBodyParams = Membership.omit({});
export const schemaMembershipPublic = Membership.omit({});
export const withValidMembership = withValidation({
schema: schemaMembershipBodyParams,
type: "Zod",
mode: "body",
});
export { schemaMembership, withValidMembership };
+8 -6
View File
@@ -1,11 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaPayment = z.object({}).strict();
const withValidPayment = withValidation({
schema: schemaPayment,
import { _PaymentModel as Payment } from "@calcom/prisma/zod";
export const schemaPaymentBodyParams = Payment.omit({ id: true });
export const schemaPaymentPublic = Payment.omit({});
export const withValidPayment = withValidation({
schema: schemaPaymentBodyParams,
type: "Zod",
mode: "body",
});
export { schemaPayment, withValidPayment };
+8 -6
View File
@@ -1,11 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaSchedule = z.object({}).strict();
const withValidSchedule = withValidation({
schema: schemaSchedule,
import { _ScheduleModel as Schedule } from "@calcom/prisma/zod";
export const schemaScheduleBodyParams = Schedule.omit({ id: true });
export const schemaSchedulePublic = Schedule.omit({});
export const withValidSchedule = withValidation({
schema: schemaScheduleBodyParams,
type: "Zod",
mode: "body",
});
export { schemaSchedule, withValidSchedule };
+7 -6
View File
@@ -1,12 +1,13 @@
import { withValidation } from "next-validations";
import { z } from "zod";
const schemaWebhook = z.object({}).strict();
import { _WebhookModel as Webhook } from "@calcom/prisma/zod";
const withValidWebhook = withValidation({
schema: schemaWebhook,
export const schemaWebhookBodyParams = Webhook.omit({ id: true });
export const schemaWebhookPublic = Webhook.omit({});
export const withValidWebhook = withValidation({
schema: schemaWebhookBodyParams,
type: "Zod",
mode: "body",
});
export { schemaWebhook, withValidWebhook };