d82f87aa2a
* wip * refactor(emails): remove circular dependencies from packages/emails - Extract renderEmail imports to use direct path (../src/renderEmail) instead of index - Create utility files for shared types and functions: - lib/utils/team-invite-utils.ts: TeamInvite type and utility functions - lib/utils/booking-redirect-types.ts: IBookingRedirect type - lib/utils/email-types.ts: OrganizationCreation and EmailVerifyCode types - lib/utils/date-formatting.ts: getFormattedDate utility function - Update all template files to import renderEmail directly from ../src/renderEmail - Update React template components to import from utility files instead of class templates - This eliminates all circular dependencies within packages/emails (reduced from 234 to 0 internal circular deps) Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * refactor(trpc): remove circular dependency in routing-forms - Extract ZFormByResponseIdInputSchema to separate schema file - Create getResponseWithFormFields.schema.ts to break circular dependency - Update imports in _router.ts and getResponseWithFormFields.handler.ts - Fix eslint warnings by updating deprecated rule names - This eliminates the circular dependency within packages/trpc (reduced from 1 to 0 internal circular deps) Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix(emails): correct TeamInvite type definition - Make isExistingUserMovedToOrg required (not optional) - Make prevLink and newLink non-optional (string | null) - Add back JSDoc comment for isAutoJoin field - This fixes type check errors in CI Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * wip * Fixes types folder --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
import type { z } from "zod";
|
|
|
|
import { enrichFormWithMigrationData } from "@calcom/app-store/routing-forms/enrichFormWithMigrationData";
|
|
import { getSerializableForm } from "@calcom/app-store/routing-forms/lib/getSerializableForm";
|
|
import type { FormResponse } from "@calcom/app-store/routing-forms/types/types";
|
|
import { canAccessEntity } from "@calcom/features/pbac/lib/entityPermissionUtils.server";
|
|
import { getTranslation } from "@calcom/lib/server/i18n";
|
|
import { prisma } from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { ZFormByResponseIdInputSchema } from "./getResponseWithFormFields.schema";
|
|
|
|
type GetResponseWithFormFieldsOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: z.infer<typeof ZFormByResponseIdInputSchema>;
|
|
};
|
|
|
|
async function getResponseWithFormFieldsHandler({ ctx, input }: GetResponseWithFormFieldsOptions) {
|
|
const { user } = ctx;
|
|
const { formResponseId } = input;
|
|
const translate = await getTranslation(user.locale ?? "en", "common");
|
|
|
|
const formResponse = await prisma.app_RoutingForms_FormResponse.findUnique({
|
|
where: {
|
|
id: formResponseId,
|
|
},
|
|
include: {
|
|
form: {
|
|
include: {
|
|
user: {
|
|
select: {
|
|
id: true,
|
|
movedToProfileId: true,
|
|
organization: {
|
|
select: {
|
|
slug: true,
|
|
},
|
|
},
|
|
username: true,
|
|
theme: true,
|
|
brandColor: true,
|
|
darkBrandColor: true,
|
|
metadata: true,
|
|
},
|
|
},
|
|
team: {
|
|
select: {
|
|
id: true,
|
|
members: true,
|
|
slug: true,
|
|
parent: {
|
|
select: { slug: true },
|
|
},
|
|
parentId: true,
|
|
metadata: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!formResponse) {
|
|
throw new TRPCError({
|
|
code: "NOT_FOUND",
|
|
message: translate("form_response_not_found"),
|
|
});
|
|
}
|
|
|
|
const form = formResponse.form;
|
|
|
|
// TODO: To make the check stricter, we could check if the user is admin/owner of the team or a member that is the organizer.
|
|
// But the exact criteria of showing a booking to the user could be trickier. Maybe we allow hosts as well to access the booking and thus should allow them as well to reroute
|
|
if (!(await canAccessEntity(form, user.id))) {
|
|
throw new TRPCError({
|
|
code: "FORBIDDEN",
|
|
message: translate("you_dont_have_access_to_reroute_this_booking"),
|
|
});
|
|
}
|
|
|
|
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
|
const userRepo = new UserRepository(prisma);
|
|
const formWithUserProfile = {
|
|
...form,
|
|
user: await userRepo.enrichUserWithItsProfile({ user: form.user }),
|
|
};
|
|
|
|
return {
|
|
response: formResponse.response as FormResponse,
|
|
form: await getSerializableForm({ form: enrichFormWithMigrationData(formWithUserProfile) }),
|
|
};
|
|
}
|
|
|
|
export default getResponseWithFormFieldsHandler;
|