* 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 <[email protected]>
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import prisma from "@calcom/prisma";
|
|
|
|
import type {
|
|
TransactionInterface,
|
|
TransactionContext,
|
|
TransactionalPhoneNumberRepository,
|
|
} from "../interfaces/TransactionInterface";
|
|
|
|
/**
|
|
* Prisma implementation of the transaction interface
|
|
* This adapter handles Prisma-specific transaction logic while keeping the provider decoupled
|
|
*/
|
|
export class PrismaTransactionAdapter implements TransactionInterface {
|
|
async executeInTransaction<T>(operations: (context: TransactionContext) => Promise<T>): Promise<T> {
|
|
return await prisma.$transaction(async (tx) => {
|
|
const transactionalPhoneNumberRepo: TransactionalPhoneNumberRepository = {
|
|
async createPhoneNumber(params) {
|
|
await tx.calAiPhoneNumber.create({
|
|
data: {
|
|
phoneNumber: params.phoneNumber,
|
|
userId: params.userId,
|
|
provider: params.provider,
|
|
teamId: params.teamId,
|
|
outboundAgentId: params.outboundAgentId,
|
|
},
|
|
});
|
|
},
|
|
};
|
|
|
|
const context: TransactionContext = {
|
|
phoneNumberRepository: transactionalPhoneNumberRepo,
|
|
};
|
|
|
|
return await operations(context);
|
|
});
|
|
}
|
|
}
|