Skip to content

Commit dbbf3ae

Browse files
fix: extract Prisma.sql queries for $queryRaw calls with Prisma.sql parameters (Prisma v6 upgrade) (calcom#23779)
* fix: extract Prisma.sql queries for calls with Prisma.sql parameters - Extract SQL queries to separate Prisma.sql variables before passing to - Fix PrismaPhoneNumberRepository.ts findManyWithUserAccess and findPhoneNumbersFromUserId methods - Fix PrismaAgentRepository.ts multiple methods with whereCondition parameters - Fix PermissionRepository.ts checkRolePermissions and getTeamIdsWithPermissions methods - Fix virtual-queues.ts getUserRelevantTeamRoutingForms method - Fix tasker/repository.ts hasNewerScanTaskForStepId method - Add missing Prisma imports where needed - Fix lint warnings: replace any with JsonValue and use explicit select for permissions - Skip primitive parameter cases as instructed - Compatible with Prisma v6 requirements Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * revert unnecessary changes --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent c3985e3 commit dbbf3ae

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

packages/lib/server/repository/PrismaAgentRepository.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class PrismaAgentRepository {
9090
whereCondition = Prisma.sql`id = ${agentId} AND "userId" = ${userId}`;
9191
}
9292

93-
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
93+
const query = Prisma.sql`
9494
SELECT
9595
id,
9696
name,
@@ -105,6 +105,8 @@ export class PrismaAgentRepository {
105105
LIMIT 1
106106
`;
107107

108+
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
109+
108110
return agents.length > 0 ? agents[0] : null;
109111
}
110112

@@ -126,7 +128,7 @@ export class PrismaAgentRepository {
126128
whereCondition = Prisma.sql`"providerAgentId" = ${providerAgentId} AND "userId" = ${userId}`;
127129
}
128130

129-
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
131+
const query = Prisma.sql`
130132
SELECT
131133
id,
132134
name,
@@ -141,6 +143,8 @@ export class PrismaAgentRepository {
141143
LIMIT 1
142144
`;
143145

146+
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
147+
144148
return agents.length > 0 ? agents[0] : null;
145149
}
146150

@@ -227,7 +231,7 @@ export class PrismaAgentRepository {
227231
}
228232
}
229233

230-
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
234+
const query = Prisma.sql`
231235
SELECT
232236
a.id,
233237
a.name,
@@ -251,6 +255,8 @@ export class PrismaAgentRepository {
251255
ORDER BY a."teamId" ASC, a."createdAt" DESC
252256
`;
253257

258+
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
259+
254260
// Get phone numbers for each agent in a separate query to avoid N+1
255261
const agentIds = agents.map((agent) => agent.id);
256262
const phoneNumbers =
@@ -343,7 +349,7 @@ export class PrismaAgentRepository {
343349
whereCondition = Prisma.sql`a.id = ${id} AND a."userId" = ${userId}`;
344350
}
345351

346-
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
352+
const query = Prisma.sql`
347353
SELECT
348354
a.id,
349355
a.name,
@@ -366,6 +372,8 @@ export class PrismaAgentRepository {
366372
LIMIT 1
367373
`;
368374

375+
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
376+
369377
if (agents.length === 0) {
370378
return null;
371379
}
@@ -464,7 +472,7 @@ export class PrismaAgentRepository {
464472
whereCondition = Prisma.sql`id = ${id} AND "userId" = ${userId}`;
465473
}
466474

467-
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
475+
const query = Prisma.sql`
468476
SELECT
469477
id,
470478
name,
@@ -479,6 +487,8 @@ export class PrismaAgentRepository {
479487
LIMIT 1
480488
`;
481489

490+
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
491+
482492
return agents.length > 0 ? agents[0] : null;
483493
}
484494

@@ -494,7 +504,7 @@ export class PrismaAgentRepository {
494504
whereCondition = Prisma.sql`a.id = ${id} AND a."userId" = ${userId}`;
495505
}
496506

497-
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
507+
const query = Prisma.sql`
498508
SELECT
499509
a.id,
500510
a.name,
@@ -509,6 +519,8 @@ export class PrismaAgentRepository {
509519
LIMIT 1
510520
`;
511521

522+
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
523+
512524
if (agents.length === 0) {
513525
return null;
514526
}

packages/lib/server/repository/PrismaPhoneNumberRepository.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export class PrismaPhoneNumberRepository {
354354
}
355355
}
356356

357-
const phoneNumbers = await prisma.$queryRaw<_PhoneNumberRawResult[]>`
357+
const query = Prisma.sql`
358358
SELECT
359359
pn.id,
360360
pn."phoneNumber",
@@ -373,6 +373,8 @@ export class PrismaPhoneNumberRepository {
373373
ORDER BY pn."createdAt" DESC
374374
`;
375375

376+
const phoneNumbers = await prisma.$queryRaw<_PhoneNumberRawResult[]>(query);
377+
376378
const phoneNumberIds = phoneNumbers.map((pn) => pn.id);
377379
const agents =
378380
phoneNumberIds.length > 0

0 commit comments

Comments
 (0)