refactor: Move repositories from @calcom/lib to @calcom/features domain folders (#27570)
* refactor: move repositories from lib to features domain folders - Move HolidayRepository to features/holidays/repositories - Move PrismaTrackingRepository to features/bookings/repositories - Move PrismaBookingPaymentRepository to features/bookings/repositories - Move PrismaRoutingFormResponseRepository to features/routing-forms/repositories - Move PrismaAssignmentReasonRepository to features/assignment-reason/repositories - Move VerificationTokenRepository to features/auth/repositories - Move WorkspacePlatformRepository to features/workspace-platform/repositories - Move DTO files to their respective feature domains - Merge lib DestinationCalendarRepository into features version - Merge lib SelectedCalendarRepository into features version - Update all import paths across the codebase This follows the vertical slice architecture pattern by organizing repositories by domain rather than by technical layer. Co-Authored-By: [email protected] <[email protected]> * fix: update VerificationTokenService import path to new location Co-Authored-By: [email protected] <[email protected]> * fix: update test file imports to use new repository locations Co-Authored-By: [email protected] <[email protected]> * mv * fix structure * fix * refactor: merge unit tests for SelectedCalendarRepository into single file Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
d4a059033e
commit
96bec9f7b9
78 files changed
+1027
-1036
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { PrismaRoutingFormResponseRepository } from "@calcom/lib/server/repository/PrismaRoutingFormResponseRepository";
|
||||
import { PrismaRoutingFormResponseRepository } from "@calcom/features/routing-forms/repositories/PrismaRoutingFormResponseRepository";
|
||||
import { ROUTING_FORM_DI_TOKENS } from "@calcom/features/routing-forms/di/tokens";
|
||||
import { bindModuleToClassOnToken } from "@calcom/features/di/di";
|
||||
import { moduleLoader as prismaModuleLoader } from "@calcom/features/di/modules/Prisma";
|
||||
|
||||
@@ -7,7 +7,7 @@ import routerGetCrmContactOwnerEmail from "@calcom/app-store/routing-forms/lib/c
|
||||
import type { TargetRoutingFormForResponse } from "@calcom/app-store/routing-forms/lib/formSubmissionUtils";
|
||||
import { onSubmissionOfFormResponse } from "@calcom/app-store/routing-forms/lib/formSubmissionUtils";
|
||||
import isRouter from "@calcom/app-store/routing-forms/lib/isRouter";
|
||||
import { RoutingFormResponseRepository } from "@calcom/lib/server/repository/formResponse";
|
||||
import { RoutingFormResponseRepository } from "@calcom/features/routing-forms/repositories/RoutingFormResponseRepository";
|
||||
|
||||
import { findTeamMembersMatchingAttributeLogic } from "./findTeamMembersMatchingAttributeLogic";
|
||||
import { handleResponse } from "./handleResponse";
|
||||
@@ -16,7 +16,7 @@ vi.mock("./findTeamMembersMatchingAttributeLogic", () => ({
|
||||
findTeamMembersMatchingAttributeLogic: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/server/repository/formResponse");
|
||||
vi.mock("@calcom/features/routing-forms/repositories/RoutingFormResponseRepository");
|
||||
|
||||
const mockRoutingFormResponseRepository = {
|
||||
recordQueuedFormResponse: vi.fn(),
|
||||
|
||||
@@ -11,7 +11,7 @@ import { HttpError } from "@calcom/lib/http-error";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import { RoutingFormResponseRepository } from "@calcom/lib/server/repository/formResponse";
|
||||
import { RoutingFormResponseRepository } from "@calcom/features/routing-forms/repositories/RoutingFormResponseRepository";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { RoutingFormResponseRepositoryInterface } from "./RoutingFormResponseRepository.interface";
|
||||
|
||||
export class PrismaRoutingFormResponseRepository implements RoutingFormResponseRepositoryInterface {
|
||||
constructor(private readonly prismaClient: PrismaClient = prisma) {}
|
||||
|
||||
findByIdIncludeForm(id: number) {
|
||||
return this.prismaClient.app_RoutingForms_FormResponse.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
form: {
|
||||
select: {
|
||||
fields: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
findByBookingUidIncludeForm(bookingUid: string) {
|
||||
return this.prismaClient.app_RoutingForms_FormResponse.findUnique({
|
||||
where: {
|
||||
routedToBookingUid: bookingUid,
|
||||
},
|
||||
include: {
|
||||
form: {
|
||||
select: {
|
||||
fields: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import type { App_RoutingForms_Form, App_RoutingForms_FormResponse } from "@calcom/prisma/client";
|
||||
|
||||
export interface RoutingFormResponseRepositoryInterface {
|
||||
findByIdIncludeForm(
|
||||
id: number
|
||||
): Promise<(App_RoutingForms_FormResponse & { form: { fields: App_RoutingForms_Form["fields"] } }) | null>;
|
||||
|
||||
findByBookingUidIncludeForm(
|
||||
bookingUid: string
|
||||
): Promise<(App_RoutingForms_FormResponse & { form: { fields: App_RoutingForms_Form["fields"] } }) | null>;
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
interface RecordFormResponseInput {
|
||||
formId: string;
|
||||
response: Record<string, any> | Prisma.JsonValue;
|
||||
chosenRouteId: string | null;
|
||||
}
|
||||
|
||||
export class RoutingFormResponseRepository {
|
||||
constructor(private prismaClient: PrismaClient) {}
|
||||
|
||||
private generateCreateFormResponseData(
|
||||
input: RecordFormResponseInput & { queuedFormResponseId?: string | null }
|
||||
) {
|
||||
return {
|
||||
formId: input.formId,
|
||||
response: input.response as Prisma.InputJsonValue,
|
||||
chosenRouteId: input.chosenRouteId,
|
||||
...(input.queuedFormResponseId
|
||||
? {
|
||||
queuedFormResponse: {
|
||||
connect: {
|
||||
id: input.queuedFormResponseId,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
async recordFormResponse(
|
||||
input: RecordFormResponseInput & {
|
||||
queuedFormResponseId?: string | null;
|
||||
}
|
||||
) {
|
||||
return await this.prismaClient.app_RoutingForms_FormResponse.create({
|
||||
data: this.generateCreateFormResponseData(input),
|
||||
});
|
||||
}
|
||||
|
||||
async recordQueuedFormResponse(input: RecordFormResponseInput) {
|
||||
return await this.prismaClient.app_RoutingForms_QueuedFormResponse.create({
|
||||
data: this.generateCreateFormResponseData(input),
|
||||
});
|
||||
}
|
||||
|
||||
async findFormResponseIncludeForm({ routingFormResponseId }: { routingFormResponseId: number }) {
|
||||
return await this.prismaClient.app_RoutingForms_FormResponse.findUnique({
|
||||
where: {
|
||||
id: routingFormResponseId,
|
||||
},
|
||||
select: {
|
||||
response: true,
|
||||
form: {
|
||||
select: {
|
||||
routes: true,
|
||||
fields: true,
|
||||
},
|
||||
},
|
||||
chosenRouteId: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findQueuedFormResponseIncludeForm({ queuedFormResponseId }: { queuedFormResponseId: string }) {
|
||||
return await this.prismaClient.app_RoutingForms_QueuedFormResponse.findUnique({
|
||||
where: {
|
||||
id: queuedFormResponseId,
|
||||
},
|
||||
select: {
|
||||
response: true,
|
||||
form: {
|
||||
select: {
|
||||
routes: true,
|
||||
fields: true,
|
||||
},
|
||||
},
|
||||
chosenRouteId: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getQueuedFormResponseFromId(id: string) {
|
||||
return await this.prismaClient.app_RoutingForms_QueuedFormResponse.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
formId: true,
|
||||
response: true,
|
||||
chosenRouteId: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
actualResponseId: true,
|
||||
form: {
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
parentId: true,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
timeFormat: true,
|
||||
locale: true,
|
||||
},
|
||||
},
|
||||
id: true,
|
||||
description: true,
|
||||
position: true,
|
||||
routes: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
name: true,
|
||||
fields: true,
|
||||
updatedById: true,
|
||||
userId: true,
|
||||
teamId: true,
|
||||
disabled: true,
|
||||
settings: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findAllResponsesWithBooking({
|
||||
formId,
|
||||
responseId,
|
||||
createdAfter,
|
||||
createdBefore,
|
||||
}: {
|
||||
formId: string;
|
||||
responseId: number;
|
||||
createdAfter: Date;
|
||||
createdBefore: Date;
|
||||
}) {
|
||||
return await this.prismaClient.app_RoutingForms_FormResponse.findMany({
|
||||
where: {
|
||||
formId,
|
||||
createdAt: {
|
||||
gte: createdAfter,
|
||||
lt: createdBefore,
|
||||
},
|
||||
routedToBookingUid: {
|
||||
not: null,
|
||||
},
|
||||
NOT: {
|
||||
id: responseId,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
response: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user