Skip to content

Commit e003426

Browse files
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>
1 parent 287cea3 commit e003426

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

apps/api/v2/src/modules/profiles/profiles.repository.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { PrismaReadService } from "@/modules/prisma/prisma-read.service";
2+
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
23
import { Injectable } from "@nestjs/common";
34
import { v4 as uuidv4 } from "uuid";
45

56
import type { Prisma } from "@calcom/prisma/client";
67

78
@Injectable()
89
export class ProfilesRepository {
9-
constructor(private readonly dbRead: PrismaReadService) {}
10+
constructor(
11+
private readonly dbRead: PrismaReadService,
12+
private readonly dbWrite: PrismaWriteService
13+
) {}
1014

1115
async getPlatformOwnerUserId(organizationId: number) {
1216
const profile = await this.dbRead.prisma.profile.findFirst({
@@ -22,7 +26,7 @@ export class ProfilesRepository {
2226
}
2327

2428
async createProfile(orgId: number, userId: number, userOrgUsername: string) {
25-
await this.dbRead.prisma.profile.create({
29+
await this.dbWrite.prisma.profile.create({
2630
data: {
2731
uid: uuidv4(),
2832
organizationId: orgId,
@@ -33,7 +37,7 @@ export class ProfilesRepository {
3337
}
3438

3539
async updateProfile(orgId: number, userId: number, body: Prisma.ProfileUpdateInput) {
36-
return this.dbRead.prisma.profile.update({
40+
return this.dbWrite.prisma.profile.update({
3741
where: {
3842
userId_organizationId: {
3943
userId,

0 commit comments

Comments
 (0)