fix: use PrismaWriteService for write operations in ProfilesRepository (#29447) (#29468)

ProfilesRepository was routing create() and update() calls through
PrismaReadService, which silently breaks in read-replica production
environments. Added PrismaWriteService injection and routed write
operations through dbWrite, matching the existing pattern used by
TeamsRepository and other repositories.

Co-authored-by: Pranav Gawande <pranavv00@users.noreply.github.com>
Co-authored-by: Bandhan Majumder <133476557+bandhan-majumder@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-06-03 01:59:12 +05:30
1 parent 287cea3001
commit e003426580
1 file changed
+7 -3
@@ -1,4 +1,5 @@
import { PrismaReadService } from "@/modules/prisma/prisma-read.service";
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
import { Injectable } from "@nestjs/common";
import { v4 as uuidv4 } from "uuid";
@@ -6,7 +7,10 @@ import type { Prisma } from "@calcom/prisma/client";
@Injectable()
export class ProfilesRepository {
constructor(private readonly dbRead: PrismaReadService) {}
constructor(
private readonly dbRead: PrismaReadService,
private readonly dbWrite: PrismaWriteService
) {}
async getPlatformOwnerUserId(organizationId: number) {
const profile = await this.dbRead.prisma.profile.findFirst({
@@ -22,7 +26,7 @@ export class ProfilesRepository {
}
async createProfile(orgId: number, userId: number, userOrgUsername: string) {
await this.dbRead.prisma.profile.create({
await this.dbWrite.prisma.profile.create({
data: {
uid: uuidv4(),
organizationId: orgId,
@@ -33,7 +37,7 @@ export class ProfilesRepository {
}
async updateProfile(orgId: number, userId: number, body: Prisma.ProfileUpdateInput) {
return this.dbRead.prisma.profile.update({
return this.dbWrite.prisma.profile.update({
where: {
userId_organizationId: {
userId,