Files
calendar/packages/features/calAIPhone/providers/adapters/PrismaAgentRepositoryAdapter.ts
T
02c86d0268 feat: cal ai self serve architecture #1 (#22919)
* feat: cal ai self serve architecture

* chore: add package

* chore: update evnet controller

* refactor: improvements

* chore: rename

* chore: type error and naming

* chore: just set it to nul

* chore: just set it to nul

* chore: some more improvements

* chore: packate version

* fix: API v2

* chore: change name of files

* chore: add select

* chore: add missing teamId

* chore: save progress

* refactor: split into multiple services

* refactor: make schema provider agonistic

* chore: improvements

* chore:

* chore: remove duplicate files

* chore: semicolon

* chore: formatting

* refactor: logging and error handling

* chore: rename variable

* refactor: use trpc error

* chore: replace with HttpError

* chore: remove from option

* We need the enum and not just the type

---------

Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
2025-08-08 15:57:13 +00:00

78 lines
2.4 KiB
TypeScript

import { PrismaAgentRepository } from "@calcom/lib/server/repository/PrismaAgentRepository";
import type {
AgentRepositoryInterface,
AgentData,
AgentWithDetailsData,
AgentWithPhoneNumbersData,
} from "../interfaces/AgentRepositoryInterface";
/**
* Adapter that bridges the provider interface to the Prisma implementation
* This adapter provides a clean abstraction layer between provider and application
*/
export class PrismaAgentRepositoryAdapter implements AgentRepositoryInterface {
async canManageTeamResources(params: { userId: number; teamId: number }): Promise<boolean> {
return await PrismaAgentRepository.canManageTeamResources(params);
}
async findByIdWithUserAccess(params: { agentId: string; userId: number }): Promise<AgentData | null> {
return await PrismaAgentRepository.findByIdWithUserAccess(params);
}
async findByProviderAgentIdWithUserAccess(params: {
providerAgentId: string;
userId: number;
}): Promise<AgentData | null> {
return await PrismaAgentRepository.findByProviderAgentIdWithUserAccess(params);
}
async findManyWithUserAccess(params: {
userId: number;
teamId?: number;
scope?: "personal" | "team" | "all";
}): Promise<AgentWithDetailsData[]> {
return await PrismaAgentRepository.findManyWithUserAccess(params);
}
async findByIdWithUserAccessAndDetails(params: {
id: string;
userId: number;
teamId?: number;
}): Promise<AgentWithDetailsData | null> {
return await PrismaAgentRepository.findByIdWithUserAccessAndDetails(params);
}
async create(params: {
name: string;
providerAgentId: string;
userId: number;
teamId?: number;
}): Promise<AgentData> {
return await PrismaAgentRepository.create(params);
}
async findByIdWithAdminAccess(params: {
id: string;
userId: number;
teamId?: number;
}): Promise<AgentData | null> {
return await PrismaAgentRepository.findByIdWithAdminAccess(params);
}
async findByIdWithCallAccess(params: {
id: string;
userId: number;
}): Promise<AgentWithPhoneNumbersData | null> {
return await PrismaAgentRepository.findByIdWithCallAccess(params);
}
async delete(params: { id: string }): Promise<void> {
await PrismaAgentRepository.delete(params);
}
async linkToWorkflowStep(params: { workflowStepId: number; agentId: string }): Promise<void> {
await PrismaAgentRepository.linkToWorkflowStep(params);
}
}