* refactor: convert RoutingFormResponseRepository to use dependency injection pattern - Add constructor with PrismaClient dependency injection - Convert all 5 static methods to instance methods using this.prismaClient - Convert private static helper method generateCreateFormResponseData to instance method - Update all usage sites to use two-step instantiation pattern: const formResponseRepo = new RoutingFormResponseRepository(prisma); formResponseRepo.method(...) - Update test files to use proper mock implementation with vi.mocked pattern - Reuse repository instances within same function scope where multiple calls are made - Follow same dependency injection pattern as UserRepository, TeamRepository, SelectedSlotsRepository, BookingRepository, and EventTypeRepository Co-Authored-By: morgan@cal.com <morgan@cal.com> * fix: resolve inconsistent dependency injection in AvailableSlotsService - Use two-step instantiation pattern for UserRepository calls - Continue fixing remaining repository instantiation inconsistencies Co-Authored-By: morgan@cal.com <morgan@cal.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: morgan@cal.com <morgan@cal.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
129 lines
3.2 KiB
TypeScript
129 lines
3.2 KiB
TypeScript
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,
|
|
},
|
|
},
|
|
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,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
}
|