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:
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,
|
||||
|
||||
Reference in new issue
Block a user