fix: extract Prisma.sql queries for $queryRaw calls with Prisma.sql parameters (Prisma v6 upgrade) (#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>
This commit is contained in:
Eunjae Lee
2025-09-11 23:18:12 +01:00
committed by GitHub
co-authored by eunjae@cal.com <hey@eunjae.dev> Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent c3985e3efb
commit dbbf3ae2a2
2 changed files with 21 additions and 7 deletions
@@ -90,7 +90,7 @@ export class PrismaAgentRepository {
whereCondition = Prisma.sql`id = ${agentId} AND "userId" = ${userId}`;
}
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
const query = Prisma.sql`
SELECT
id,
name,
@@ -105,6 +105,8 @@ export class PrismaAgentRepository {
LIMIT 1
`;
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
return agents.length > 0 ? agents[0] : null;
}
@@ -126,7 +128,7 @@ export class PrismaAgentRepository {
whereCondition = Prisma.sql`"providerAgentId" = ${providerAgentId} AND "userId" = ${userId}`;
}
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
const query = Prisma.sql`
SELECT
id,
name,
@@ -141,6 +143,8 @@ export class PrismaAgentRepository {
LIMIT 1
`;
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
return agents.length > 0 ? agents[0] : null;
}
@@ -227,7 +231,7 @@ export class PrismaAgentRepository {
}
}
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
const query = Prisma.sql`
SELECT
a.id,
a.name,
@@ -251,6 +255,8 @@ export class PrismaAgentRepository {
ORDER BY a."teamId" ASC, a."createdAt" DESC
`;
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
// Get phone numbers for each agent in a separate query to avoid N+1
const agentIds = agents.map((agent) => agent.id);
const phoneNumbers =
@@ -343,7 +349,7 @@ export class PrismaAgentRepository {
whereCondition = Prisma.sql`a.id = ${id} AND a."userId" = ${userId}`;
}
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
const query = Prisma.sql`
SELECT
a.id,
a.name,
@@ -366,6 +372,8 @@ export class PrismaAgentRepository {
LIMIT 1
`;
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
if (agents.length === 0) {
return null;
}
@@ -464,7 +472,7 @@ export class PrismaAgentRepository {
whereCondition = Prisma.sql`id = ${id} AND "userId" = ${userId}`;
}
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
const query = Prisma.sql`
SELECT
id,
name,
@@ -479,6 +487,8 @@ export class PrismaAgentRepository {
LIMIT 1
`;
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
return agents.length > 0 ? agents[0] : null;
}
@@ -494,7 +504,7 @@ export class PrismaAgentRepository {
whereCondition = Prisma.sql`a.id = ${id} AND a."userId" = ${userId}`;
}
const agents = await prisma.$queryRaw<_AgentRawResult[]>`
const query = Prisma.sql`
SELECT
a.id,
a.name,
@@ -509,6 +519,8 @@ export class PrismaAgentRepository {
LIMIT 1
`;
const agents = await prisma.$queryRaw<_AgentRawResult[]>(query);
if (agents.length === 0) {
return null;
}
@@ -354,7 +354,7 @@ export class PrismaPhoneNumberRepository {
}
}
const phoneNumbers = await prisma.$queryRaw<_PhoneNumberRawResult[]>`
const query = Prisma.sql`
SELECT
pn.id,
pn."phoneNumber",
@@ -373,6 +373,8 @@ export class PrismaPhoneNumberRepository {
ORDER BY pn."createdAt" DESC
`;
const phoneNumbers = await prisma.$queryRaw<_PhoneNumberRawResult[]>(query);
const phoneNumberIds = phoneNumbers.map((pn) => pn.id);
const agents =
phoneNumberIds.length > 0