fix: calcom trpc circle deps slots handlers (#19896)
* remove validator file and include inside handler * fixes slots and handler circle dep * fix type in tests
This commit is contained in:
1 parent
fd454061e7
commit
e89211782c
6 files changed
+36
-40
No files matched your search
@@ -11,8 +11,7 @@ import { describe, test, beforeEach, vi } from "vitest";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { GetScheduleOptions } from "@calcom/trpc/server/routers/viewer/slots/getSchedule.handler";
|
||||
import type { getScheduleSchema } from "@calcom/trpc/server/routers/viewer/slots/types";
|
||||
import type { getScheduleSchema, GetScheduleOptions } from "@calcom/trpc/server/routers/viewer/slots/types";
|
||||
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||
|
||||
import { expect } from "./expects";
|
||||
|
||||
@@ -5,7 +5,6 @@ import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../trpc";
|
||||
import type { TUpdateAppCredentialsInputSchema } from "./updateAppCredentials.schema";
|
||||
import { handleCustomValidations } from "./updateAppCredentials.validator";
|
||||
|
||||
export type UpdateAppCredentialsOptions = {
|
||||
ctx: {
|
||||
@@ -14,6 +13,27 @@ export type UpdateAppCredentialsOptions = {
|
||||
input: TUpdateAppCredentialsInputSchema;
|
||||
};
|
||||
|
||||
const validators = {
|
||||
paypal: () => import("@calcom/paypal/lib/updateAppCredentials.validator"),
|
||||
};
|
||||
|
||||
export const handleCustomValidations = async ({
|
||||
ctx,
|
||||
input,
|
||||
appId,
|
||||
}: UpdateAppCredentialsOptions & { appId: string }) => {
|
||||
const { key } = input;
|
||||
const validatorGetter = validators[appId as keyof typeof validators];
|
||||
// If no validator is found, return the key as is
|
||||
if (!validatorGetter) return key;
|
||||
try {
|
||||
const validator = (await validatorGetter()).default;
|
||||
return await validator({ input, ctx });
|
||||
} catch (error) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST" });
|
||||
}
|
||||
};
|
||||
|
||||
export const updateAppCredentialsHandler = async ({ ctx, input }: UpdateAppCredentialsOptions) => {
|
||||
const { user } = ctx;
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { UpdateAppCredentialsOptions } from "./updateAppCredentials.handler";
|
||||
|
||||
const validators = {
|
||||
paypal: () => import("@calcom/paypal/lib/updateAppCredentials.validator"),
|
||||
};
|
||||
|
||||
export const handleCustomValidations = async ({
|
||||
ctx,
|
||||
input,
|
||||
appId,
|
||||
}: UpdateAppCredentialsOptions & { appId: string }) => {
|
||||
const { key } = input;
|
||||
const validatorGetter = validators[appId as keyof typeof validators];
|
||||
// If no validator is found, return the key as is
|
||||
if (!validatorGetter) return key;
|
||||
try {
|
||||
const validator = (await validatorGetter()).default;
|
||||
return await validator({ input, ctx });
|
||||
} catch (error) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST" });
|
||||
}
|
||||
};
|
||||
@@ -1,17 +1,6 @@
|
||||
import type { IncomingMessage } from "http";
|
||||
|
||||
import type { TGetScheduleInputSchema } from "./getSchedule.schema";
|
||||
import type { GetScheduleOptions } from "./types";
|
||||
import { getAvailableSlots } from "./util";
|
||||
|
||||
export type GetScheduleOptions = {
|
||||
ctx?: ContextForGetSchedule;
|
||||
input: TGetScheduleInputSchema;
|
||||
};
|
||||
|
||||
interface ContextForGetSchedule extends Record<string, unknown> {
|
||||
req?: (IncomingMessage & { cookies: Partial<{ [key: string]: string }> }) | undefined;
|
||||
}
|
||||
|
||||
export const getScheduleHandler = async ({ ctx, input }: GetScheduleOptions) => {
|
||||
return await getAvailableSlots({ ctx, input });
|
||||
};
|
||||
@@ -1,5 +1,8 @@
|
||||
import type { IncomingMessage } from "http";
|
||||
import { z } from "zod";
|
||||
|
||||
import type { TGetScheduleInputSchema } from "./getSchedule.schema";
|
||||
|
||||
export const getScheduleSchema = z
|
||||
.object({
|
||||
// startTime ISOString
|
||||
@@ -74,3 +77,12 @@ export type Slot = {
|
||||
export const removeSelectedSlotSchema = z.object({
|
||||
uid: z.string().nullable(),
|
||||
});
|
||||
|
||||
export interface ContextForGetSchedule extends Record<string, unknown> {
|
||||
req?: (IncomingMessage & { cookies: Partial<{ [key: string]: string }> }) | undefined;
|
||||
}
|
||||
|
||||
export type GetScheduleOptions = {
|
||||
ctx?: ContextForGetSchedule;
|
||||
input: TGetScheduleInputSchema;
|
||||
};
|
||||
@@ -40,9 +40,9 @@ import type { CredentialPayload, CredentialForCalendarService } from "@calcom/ty
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { GetScheduleOptions } from "./getSchedule.handler";
|
||||
import type { TGetScheduleInputSchema } from "./getSchedule.schema";
|
||||
import { handleNotificationWhenNoSlots } from "./handleNotificationWhenNoSlots";
|
||||
import type { GetScheduleOptions } from "./types";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["[slots/util]"] });
|
||||
type GetAvailabilityUserWithoutDelegationCredentials = Omit<GetAvailabilityUser, "credentials"> & {
|
||||
|
||||
Reference in new issue
Block a user