refactor: convert EventTypeRepository to use dependency injection pattern (#22397)

- Add constructor with PrismaClient dependency injection
- Convert all 14 static methods to instance methods using this.prismaClient
- Update all usage sites to use two-step instantiation pattern:
  const eventTypeRepo = new EventTypeRepository(prisma); eventTypeRepo.method(...)
- Keep getSelectedCalendarsFromUser as static utility method
- Follow same pattern as UserRepository, TeamRepository, SelectedSlotsRepository, and BookingRepository
- Maintain all existing method signatures and functionality

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: [email protected] <[email protected]>
This commit is contained in:
devin-ai-integration[bot]and[email protected] authored and GitHub committed 2025-07-11 10:39:22 +03:00
1 parent b5911a9a2d
commit 758143ef70
14 files changed
+68 -59

No files matched your search

@@ -126,7 +126,8 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
const profile = ctx.user.profile;
try {
const eventType = await EventTypeRepository.create({
const eventTypeRepo = new EventTypeRepository(ctx.prisma);
const eventType = await eventTypeRepo.create({
...data,
profileId: profile.id,
});
@@ -151,7 +151,8 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
}
}
const newEventType = await EventTypeRepository.create(data);
const eventTypeRepo = new EventTypeRepository(prisma);
const newEventType = await eventTypeRepo.create(data);
// Create custom inputs
if (customInputs) {
@@ -21,7 +21,7 @@ type GetByViewerOptions = {
input: TGetEventTypesFromGroupSchema;
};
type EventType = Awaited<ReturnType<typeof EventTypeRepository.findAllByUpId>>[number];
type EventType = Awaited<ReturnType<EventTypeRepository["findAllByUpId"]>>[number];
type MappedEventType = Awaited<ReturnType<typeof mapEventType>>;
export const getEventTypesFromGroup = async ({
@@ -47,6 +47,7 @@ export const getEventTypesFromGroup = async ({
!isFilterSet || isUpIdInFilter || (isFilterSet && filters?.upIds && !isUpIdInFilter);
const eventTypes: EventType[] = [];
const eventTypeRepo = new EventTypeRepository(ctx.prisma);
if (shouldListUserEvents || !teamId) {
const baseQueryConditions = {
@@ -56,7 +57,7 @@ export const getEventTypesFromGroup = async ({
};
const [nonChildEventTypes, childEventTypes] = await Promise.all([
EventTypeRepository.findAllByUpId(
eventTypeRepo.findAllByUpId(
{
upId: userProfile.upId,
userId: ctx.user.id,
@@ -78,7 +79,7 @@ export const getEventTypesFromGroup = async ({
cursor,
}
),
EventTypeRepository.findAllByUpId(
eventTypeRepo.findAllByUpId(
{
upId: userProfile.upId,
userId: ctx.user.id,
@@ -117,7 +118,7 @@ export const getEventTypesFromGroup = async ({
if (teamId) {
const teamEventTypes =
(await EventTypeRepository.findTeamEventTypes({
(await eventTypeRepo.findTeamEventTypes({
teamId,
parentId,
userId: ctx.user.id,
@@ -53,6 +53,7 @@ export const getTeamAndEventTypeOptions = async ({ ctx, input }: GetTeamAndEvent
const parentOrgHasLockedEventTypes =
profile?.organization?.organizationSettings?.lockEventTypeCreationForUsers;
const eventTypeRepo = new EventTypeRepository(ctx.prisma);
const [profileMemberships, profileEventTypes] = await Promise.all([
MembershipRepository.findAllByUpIdIncludeMinimalEventTypes(
{
@@ -67,7 +68,7 @@ export const getTeamAndEventTypeOptions = async ({ ctx, input }: GetTeamAndEvent
),
teamId
? []
: EventTypeRepository.findAllByUpIdWithMinimalData(
: eventTypeRepo.findAllByUpIdWithMinimalData(
{
upId: userProfile.upId,
userId: user.id,
@@ -14,7 +14,7 @@ import { TRPCError } from "@trpc/server";
import authedProcedure from "../../../procedures/authedProcedure";
import type { TUpdateInputSchema } from "./types";
type EventType = Awaited<ReturnType<typeof EventTypeRepository.findAllByUpId>>[number];
type EventType = Awaited<ReturnType<EventTypeRepository["findAllByUpId"]>>[number];
export const eventOwnerProcedure = authedProcedure
.input(
@@ -177,7 +177,8 @@ export const findTeamMembersMatchingAttributeLogicOfRouteHandler = async ({
});
}
const eventType = await EventTypeRepository.findByIdIncludeHostsAndTeam({ id: eventTypeId });
const eventTypeRepo = new EventTypeRepository(prisma);
const eventType = await eventTypeRepo.findByIdIncludeHostsAndTeam({ id: eventTypeId });
if (!eventType) {
throw new TRPCError({
@@ -32,7 +32,8 @@ export const isAvailableHandler = async ({
const { slots, eventTypeId } = input;
// Get event type details for time bounds validation
const eventType = await EventTypeRepository.findByIdMinimal({ id: eventTypeId });
const eventTypeRepo = new EventTypeRepository(ctx.prisma);
const eventType = await eventTypeRepo.findByIdMinimal({ id: eventTypeId });
if (!eventType) {
throw new HttpError({ statusCode: 404, message: "Event type not found" });
@@ -211,7 +211,8 @@ export class AvailableSlotsService {
return null;
}
return await EventTypeRepository.findForSlots({ id: eventTypeId });
const eventTypeRepo = new EventTypeRepository(prisma);
return await eventTypeRepo.findForSlots({ id: eventTypeId });
}
private getEventType = withReporting(this._getEventType.bind(this), "getEventType");
@@ -281,7 +282,8 @@ export class AvailableSlotsService {
organizationDetails ?? { currentOrgDomain: null, isValidOrgDomain: false }
);
}
const eventType = await EventTypeRepository.findFirstEventTypeId({ slug: eventTypeSlug, teamId, userId });
const eventTypeRepo = new EventTypeRepository(prisma);
const eventType = await eventTypeRepo.findFirstEventTypeId({ slug: eventTypeSlug, teamId, userId });
if (!eventType) {
throw new TRPCError({ code: "NOT_FOUND" });
}