Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/features/insights/hooks/useInsightsOrgTeams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useInsightsOrgTeams() {
const teamId = orgTeamsType === "org" ? currentOrgId : orgTeamsType === "team" ? selectedTeamId : undefined;
const userId = orgTeamsType === "yours" ? session.data?.user.id : undefined;

// Adding `scope` for InsightsRoutingService
// Adding `scope` for InsightsRoutingBaseService
// (renaming 'yours' to 'user')
const scope: "org" | "team" | "user" = orgTeamsType === "yours" ? "user" : orgTeamsType;

Expand Down
5 changes: 2 additions & 3 deletions packages/features/insights/server/trpc-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
routingRepositoryBaseInputSchema,
bookingRepositoryBaseInputSchema,
} from "@calcom/features/insights/server/raw-data.schema";
import { getInsightsRoutingService } from "@calcom/lib/di/containers/insights-routing";
import { InsightsBookingService } from "@calcom/lib/server/service/insightsBooking";
import { InsightsRoutingService } from "@calcom/lib/server/service/insightsRouting";
import type { readonlyPrisma } from "@calcom/prisma";
import { BookingStatus } from "@calcom/prisma/enums";
import authedProcedure from "@calcom/trpc/server/procedures/authedProcedure";
Expand Down Expand Up @@ -1742,8 +1742,7 @@ export const insightsRouter = router({
timeView,
weekStart: ctx.user.weekStart,
});
const insightsRoutingService = new InsightsRoutingService({
prisma: ctx.insightsDb,
const insightsRoutingService = getInsightsRoutingService({
options: {
scope: input.scope,
teamId: input.selectedTeamId,
Expand Down
27 changes: 27 additions & 0 deletions packages/lib/di/containers/insights-routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createContainer } from "@evyweb/ioctopus";

import { DI_TOKENS } from "@calcom/lib/di/tokens";
import type {
InsightsRoutingServicePublicOptions,
InsightsRoutingServiceFilterOptions,
InsightsRoutingBaseService,
} from "@calcom/lib/server/service/insightsRoutingBase";
import type { InsightsRoutingService } from "@calcom/lib/server/service/insightsRoutingDI";
import { prismaModule } from "@calcom/prisma/prisma.module";

import { insightsRoutingModule } from "../modules/insights-routing";

export function getInsightsRoutingService({
options,
filters,
}: {
options: InsightsRoutingServicePublicOptions;
filters: InsightsRoutingServiceFilterOptions;
}): InsightsRoutingBaseService {
const container = createContainer();
container.load(DI_TOKENS.READ_ONLY_PRISMA_CLIENT, prismaModule);
container.load(DI_TOKENS.INSIGHTS_ROUTING_SERVICE_MODULE, insightsRoutingModule);

const diService = container.get<InsightsRoutingService>(DI_TOKENS.INSIGHTS_ROUTING_SERVICE);
return diService.create({ options, filters });
}
11 changes: 11 additions & 0 deletions packages/lib/di/modules/insights-routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createModule } from "@evyweb/ioctopus";

import type { IInsightsRoutingService } from "@calcom/lib/server/service/insightsRoutingDI";
import { InsightsRoutingService } from "@calcom/lib/server/service/insightsRoutingDI";

import { DI_TOKENS } from "../tokens";

export const insightsRoutingModule = createModule();
insightsRoutingModule.bind(DI_TOKENS.INSIGHTS_ROUTING_SERVICE).toClass(InsightsRoutingService, {
prisma: DI_TOKENS.READ_ONLY_PRISMA_CLIENT,
} satisfies Record<keyof IInsightsRoutingService, symbol>);
2 changes: 2 additions & 0 deletions packages/lib/di/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export const DI_TOKENS = {
ROUTING_FORM_RESPONSE_REPOSITORY_MODULE: Symbol("RoutingFormResponseRepositoryModule"),
AVAILABLE_SLOTS_SERVICE: Symbol("AvailableSlotsService"),
AVAILABLE_SLOTS_SERVICE_MODULE: Symbol("AvailableSlotsModule"),
INSIGHTS_ROUTING_SERVICE: Symbol("InsightsRoutingService"),
INSIGHTS_ROUTING_SERVICE_MODULE: Symbol("InsightsRoutingServiceModule"),
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ColumnFilterType } from "@calcom/features/data-table/lib/types";
import prisma from "@calcom/prisma";
import { BookingStatus, MembershipRole } from "@calcom/prisma/enums";

import { InsightsRoutingService } from "../../service/insightsRouting";
import { InsightsRoutingBaseService as InsightsRoutingService } from "../../service/insightsRoutingBase";

// SQL condition constants for testing
const NOTHING_CONDITION = Prisma.sql`1=0`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type InsightsRoutingServiceFilterOptions = {

const NOTHING_CONDITION = Prisma.sql`1=0`;

export class InsightsRoutingService {
export class InsightsRoutingBaseService {
private prisma: typeof readonlyPrisma;
private options: InsightsRoutingServiceOptions | null;
private filters: InsightsRoutingServiceFilterOptions;
Expand Down
29 changes: 29 additions & 0 deletions packages/lib/server/service/insightsRoutingDI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { readonlyPrisma } from "@calcom/prisma";

import {
InsightsRoutingBaseService,
type InsightsRoutingServicePublicOptions,
type InsightsRoutingServiceFilterOptions,
} from "./insightsRoutingBase";

export interface IInsightsRoutingService {
prisma: typeof readonlyPrisma;
}

export class InsightsRoutingService {
constructor(private readonly dependencies: IInsightsRoutingService) {}

create({
options,
filters,
}: {
options: InsightsRoutingServicePublicOptions;
filters: InsightsRoutingServiceFilterOptions;
}): InsightsRoutingBaseService {
return new InsightsRoutingBaseService({
prisma: this.dependencies.prisma,
options,
filters,
});
}
}
Loading