Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): issue related to join[] #8301

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export class UsageInsightsService {
private readonly prisma: PrismaService
) {}

private projectIdsFilter = (projectIds: string[]) => {
let filter = Prisma.empty;
if (projectIds.length > 0) {
filter = Prisma.sql`AND r."projectId" IN (${Prisma.join(projectIds)})`;
}
return filter;
};

async countLinesOfCode({
projectIds,
startDate,
Expand Down Expand Up @@ -91,7 +99,7 @@ export class UsageInsightsService {
JOIN "Resource" r ON b."resourceId" = r."id"
WHERE b."createdAt" >= ${startDate}
AND b."createdAt" <= ${endDate}
AND r."projectId" IN (${Prisma.join(projectIds)})
${this.projectIdsFilter(projectIds)}
GROUP BY year, month, time_group
ORDER BY year, month, time_group;
`;
Expand All @@ -112,8 +120,8 @@ export class UsageInsightsService {
FROM "EntityVersion" ev
JOIN "Entity" e ON ev."entityId" = e."id"
JOIN "Resource" r ON e."resourceId" = r."id"
WHERE r."projectId" IN (${Prisma.join(projectIds)})
AND ev."updatedAt" >= ${startDate} AND ev."updatedAt" <= ${endDate}
WHERE ev."updatedAt" >= ${startDate} AND ev."updatedAt" <= ${endDate}
${this.projectIdsFilter(projectIds)}
GROUP BY year, month, time_group
ORDER BY year, month, time_group;
`;
Expand All @@ -131,7 +139,8 @@ export class UsageInsightsService {
timeGroup,
}: BlockChangesArgs): Promise<UsageInsights> {
let results: QueryRawResult[];
// Prisma query row doesn't work as expected with enums, so we use switch case instead of one query with ${blokType}

// Prisma query raw doesn't work as expected with enums, so we use switch case instead of one query with ${blockType}
switch (blockType) {
case EnumBlockType.ModuleAction:
results = await this.prisma.$queryRaw`
Expand All @@ -140,7 +149,7 @@ export class UsageInsightsService {
JOIN "Block" b ON bv."blockId" = b."id"
JOIN "Resource" r ON b."resourceId" = r."id"
WHERE b."blockType" = 'ModuleAction'
AND r."projectId" IN (${Prisma.join(projectIds)})
${this.projectIdsFilter(projectIds)}
AND bv."updatedAt" >= ${startDate} AND bv."updatedAt" <= ${endDate}
GROUP BY year, month, time_group
ORDER BY year, month, time_group;
Expand All @@ -153,7 +162,7 @@ export class UsageInsightsService {
JOIN "Block" b ON bv."blockId" = b."id"
JOIN "Resource" r ON b."resourceId" = r."id"
WHERE b."blockType" = 'PluginInstallation'
AND r."projectId" IN (${Prisma.join(projectIds)})
${this.projectIdsFilter(projectIds)}
AND bv."updatedAt" >= ${startDate} AND bv."updatedAt" <= ${endDate}
GROUP BY year, month, time_group
ORDER BY year, month, time_group;
Expand Down
Loading