diff --git a/.github/workflows/type-check.yml b/.github/workflows/type-check.yml index 69a2997013..a8c933d87e 100644 --- a/.github/workflows/type-check.yml +++ b/.github/workflows/type-check.yml @@ -1,4 +1,3 @@ - name: Check types on: pull_request: @@ -24,4 +23,4 @@ jobs: with: node-version: ${{ matrix.node }} - run: yarn - - run: yarn type-check \ No newline at end of file + - run: yarn type-check diff --git a/.prettierignore b/.prettierignore index 9e622a406d..28b23b7d57 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ .next/ coverage/ -node_modules/ \ No newline at end of file +node_modules/ +tests/ \ No newline at end of file diff --git a/lib/validations/api-key.ts b/lib/validations/api-key.ts new file mode 100644 index 0000000000..c0ffd6c9b3 --- /dev/null +++ b/lib/validations/api-key.ts @@ -0,0 +1,23 @@ +import { withValidation } from "next-validations"; +import { z } from "zod"; + +import { _ApiKeyModel as ApiKey } from "@calcom/prisma/zod"; + +export const schemaApiKeyBaseBodyParams = ApiKey.omit({ id: true, userId: true, createdAt: true }).partial(); + +const schemaApiKeyRequiredParams = z.object({ + email: z.string().email(), +}); + +export const schemaApiKeyBodyParams = schemaApiKeyBaseBodyParams.merge(schemaApiKeyRequiredParams); + +export const schemaApiKeyPublic = ApiKey.omit({ + id: true, + userId: true, +}); + +export const withValidApiKey = withValidation({ + schema: schemaApiKeyBodyParams, + type: "Zod", + mode: "body", +}); diff --git a/lib/validations/apiKey.ts b/lib/validations/apiKey.ts deleted file mode 100644 index e12a50cefa..0000000000 --- a/lib/validations/apiKey.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { withValidation } from "next-validations"; - -import { _ApiKeyModel as ApiKey } from "@calcom/prisma/zod"; - -export const schemaApiKeyBodyParams = ApiKey.omit({ id: true, userId: true, createdAt: true }).partial(); - -export const schemaApiKeyPublic = ApiKey.omit({ - id: true, - userId: true, -}); - -export const withValidApiKey = withValidation({ - schema: schemaApiKeyBodyParams, - type: "Zod", - mode: "body", -}); diff --git a/lib/validations/daily-event-reference.ts b/lib/validations/daily-event-reference.ts index da24927310..f477f6bec6 100644 --- a/lib/validations/daily-event-reference.ts +++ b/lib/validations/daily-event-reference.ts @@ -1,8 +1,17 @@ import { withValidation } from "next-validations"; +import { z } from "zod"; import { _DailyEventReferenceModel as DailyEventReference } from "@calcom/prisma/zod"; -export const schemaDailyEventReferenceBodyParams = DailyEventReference.omit({ id: true }); +export const schemaDailyEventReferenceBaseBodyParams = DailyEventReference.omit({ id: true }); + +const schemaDailyEventReferenceRequiredParams = z.object({ + email: z.string().email(), +}); + +export const schemaDailyEventReferenceBodyParams = schemaDailyEventReferenceBaseBodyParams.merge( + schemaDailyEventReferenceRequiredParams +); export const schemaDailyEventReferencePublic = DailyEventReference.omit({}); diff --git a/lib/validations/destination-calendar.ts b/lib/validations/destination-calendar.ts index 002d68d097..87e367ee19 100644 --- a/lib/validations/destination-calendar.ts +++ b/lib/validations/destination-calendar.ts @@ -1,8 +1,18 @@ import { withValidation } from "next-validations"; +import { z } from "zod"; import { _DestinationCalendarModel as DestinationCalendar } from "@calcom/prisma/zod"; -export const schemaDestinationCalendarBodyParams = DestinationCalendar.omit({ id: true }); +export const schemaDestinationCalendarBaseBodyParams = DestinationCalendar.omit({ id: true }).partial(); + +const schemaDestinationCalendarRequiredParams = z.object({ + integration: z.string(), + externalId: z.string(), +}); + +export const schemaDestinationCalendarBodyParams = schemaDestinationCalendarBaseBodyParams.merge( + schemaDestinationCalendarRequiredParams +); export const schemaDestinationCalendarPublic = DestinationCalendar.omit({}); diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts new file mode 100644 index 0000000000..113620157e --- /dev/null +++ b/lib/validations/event-type.ts @@ -0,0 +1,22 @@ +import { withValidation } from "next-validations"; +import { z } from "zod"; + +import { _EventTypeModel as EventType } from "@calcom/prisma/zod"; + +export const schemaEventTypeBaseBodyParams = EventType.omit({ id: true }).partial(); + +const schemaEventTypeRequiredParams = z.object({ + title: z.string(), + slug: z.string(), + length: z.number(), +}); + +export const schemaEventTypeBodyParams = schemaEventTypeBaseBodyParams.merge(schemaEventTypeRequiredParams); + +export const schemaEventTypePublic = EventType.omit({}); + +export const withValidEventType = withValidation({ + schema: schemaEventTypeBodyParams, + type: "Zod", + mode: "body", +}); diff --git a/lib/validations/eventType.ts b/lib/validations/eventType.ts deleted file mode 100644 index f257a4d0a8..0000000000 --- a/lib/validations/eventType.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { withValidation } from "next-validations"; - -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", -}); diff --git a/lib/validations/membership.ts b/lib/validations/membership.ts index 46444e6f86..bb5d7cb7fc 100644 --- a/lib/validations/membership.ts +++ b/lib/validations/membership.ts @@ -1,8 +1,16 @@ import { withValidation } from "next-validations"; +import { z } from "zod"; import { _MembershipModel as Membership } from "@calcom/prisma/zod"; -export const schemaMembershipBodyParams = Membership.omit({}); +export const schemaMembershipBaseBodyParams = Membership.omit({}); +const schemaMembershipRequiredParams = z.object({ + teamId: z.number(), +}); + +export const schemaMembershipBodyParams = schemaMembershipBaseBodyParams.merge( + schemaMembershipRequiredParams +); export const schemaMembershipPublic = Membership.omit({}); diff --git a/lib/validations/team.ts b/lib/validations/team.ts index 010d73282a..ec6cbf35ec 100644 --- a/lib/validations/team.ts +++ b/lib/validations/team.ts @@ -1,8 +1,13 @@ import { withValidation } from "next-validations"; +import { z } from "zod"; import { _TeamModel as Team } from "@calcom/prisma/zod"; -export const schemaTeamBodyParams = Team.omit({ id: true }).partial(); +export const schemaTeamBaseBodyParams = Team.omit({ id: true }).partial(); + +const schemaTeamRequiredParams = z.object({}); + +export const schemaTeamBodyParams = schemaTeamBaseBodyParams.merge(schemaTeamRequiredParams); export const schemaTeamPublic = Team.omit({}); diff --git a/pages/api/api-keys/[id]/edit.ts b/pages/api/api-keys/[id]/edit.ts index bbda40f7fc..66da3539bc 100644 --- a/pages/api/api-keys/[id]/edit.ts +++ b/pages/api/api-keys/[id]/edit.ts @@ -4,7 +4,7 @@ import prisma from "@calcom/prisma"; import { ApiKey } from "@calcom/prisma/client"; import { withMiddleware } from "@lib/helpers/withMiddleware"; -import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/apiKey"; +import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/api-key"; import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; type ResponseData = { diff --git a/pages/api/api-keys/new.ts b/pages/api/api-keys/new.ts index 97bd5a0b24..160324c19c 100644 --- a/pages/api/api-keys/new.ts +++ b/pages/api/api-keys/new.ts @@ -4,7 +4,7 @@ import prisma from "@calcom/prisma"; import { ApiKey } from "@calcom/prisma/client"; import { withMiddleware } from "@lib/helpers/withMiddleware"; -import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/apiKey"; +import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/api-key"; type ResponseData = { data?: ApiKey; diff --git a/pages/api/event-types/[id]/edit.ts b/pages/api/event-types/[id]/edit.ts index bb181742c0..5fad6585de 100644 --- a/pages/api/event-types/[id]/edit.ts +++ b/pages/api/event-types/[id]/edit.ts @@ -8,7 +8,7 @@ import { schemaEventTypeBodyParams, schemaEventTypePublic, withValidEventType, -} from "@lib/validations/eventType"; +} from "@lib/validations/event-type"; import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt, diff --git a/pages/api/event-types/[id]/index.ts b/pages/api/event-types/[id]/index.ts index 4e64863965..5e3ac565ae 100644 --- a/pages/api/event-types/[id]/index.ts +++ b/pages/api/event-types/[id]/index.ts @@ -4,7 +4,7 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { EventTypeResponse } from "@lib/types"; -import { schemaEventTypePublic } from "@lib/validations/eventType"; +import { schemaEventTypePublic } from "@lib/validations/event-type"; import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt, diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index a9bd50bce7..5385f3f3c4 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -4,7 +4,7 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import { EventTypesResponse } from "@lib/types"; -import { schemaEventTypePublic } from "@lib/validations/eventType"; +import { schemaEventTypePublic } from "@lib/validations/event-type"; /** * @swagger diff --git a/pages/api/event-types/new.ts b/pages/api/event-types/new.ts index e0a6bf4707..847d25dd32 100644 --- a/pages/api/event-types/new.ts +++ b/pages/api/event-types/new.ts @@ -8,7 +8,7 @@ import { schemaEventTypeBodyParams, schemaEventTypePublic, withValidEventType, -} from "@lib/validations/eventType"; +} from "@lib/validations/event-type"; /** * @swagger