fix: CSV generation from insights returns empty results (#22775)

* fix: CSV generation from insights returns empty results

* update

* fix type error
This commit is contained in:
Anik Dhabal Babu
2025-07-28 13:17:14 +00:00
committed by GitHub
parent 628b169f53
commit 9cd806ff61
2 changed files with 33 additions and 20 deletions
+16 -10
View File
@@ -261,16 +261,22 @@ export class InsightsBookingService {
if (!this.options) {
return NOTHING_CONDITION;
}
const isOwnerOrAdmin = await this.isOrgOwnerOrAdmin(this.options.userId, this.options.orgId);
if (!isOwnerOrAdmin) {
return NOTHING_CONDITION;
const scope = this.options.scope;
const targetId =
scope === "org" ? this.options.orgId : scope === "team" ? this.options.teamId : undefined;
if (targetId && scope !== "user") {
const isOwnerOrAdmin = await this.isOwnerOrAdmin(this.options.userId, targetId);
if (!isOwnerOrAdmin) {
return NOTHING_CONDITION;
}
}
if (this.options.scope === "user") {
if (scope === "user") {
return Prisma.sql`("userId" = ${this.options.userId}) AND ("teamId" IS NULL)`;
} else if (this.options.scope === "org") {
} else if (scope === "org") {
return await this.buildOrgAuthorizationCondition(this.options);
} else if (this.options.scope === "team") {
} else if (scope === "team") {
return await this.buildTeamAuthorizationCondition(this.options);
} else {
return NOTHING_CONDITION;
@@ -318,7 +324,7 @@ export class InsightsBookingService {
parentId: options.orgId,
select: { id: true },
});
if (!childTeamOfOrg) {
if (options.orgId && !childTeamOfOrg) {
return NOTHING_CONDITION;
}
@@ -659,9 +665,9 @@ export class InsightsBookingService {
return result;
}
private async isOrgOwnerOrAdmin(userId: number, orgId: number): Promise<boolean> {
// Check if the user is an owner or admin of the organization
const membership = await MembershipRepository.findUniqueByUserIdAndTeamId({ userId, teamId: orgId });
private async isOwnerOrAdmin(userId: number, targetId: number): Promise<boolean> {
// Check if the user is an owner or admin of the organization or team
const membership = await MembershipRepository.findUniqueByUserIdAndTeamId({ userId, teamId: targetId });
return Boolean(
membership &&
membership.accepted &&
@@ -306,16 +306,23 @@ export class InsightsRoutingBaseService {
if (!this.options) {
return NOTHING_CONDITION;
}
const isOwnerOrAdmin = await this.isOrgOwnerOrAdmin(this.options.userId, this.options.orgId);
if (!isOwnerOrAdmin) {
return NOTHING_CONDITION;
const scope = this.options.scope;
const targetId =
scope === "org" ? this.options.orgId : scope === "team" ? this.options.teamId : undefined;
if (targetId && scope !== "user") {
const isOwnerOrAdmin = await this.isOwnerOrAdmin(this.options.userId, targetId);
if (!isOwnerOrAdmin) {
return NOTHING_CONDITION;
}
}
if (this.options.scope === "user") {
if (scope === "user") {
return Prisma.sql`"formUserId" = ${this.options.userId} AND "formTeamId" IS NULL`;
} else if (this.options.scope === "org") {
} else if (scope === "org") {
return await this.buildOrgAuthorizationCondition(this.options);
} else if (this.options.scope === "team") {
} else if (scope === "team") {
return await this.buildTeamAuthorizationCondition(this.options);
} else {
return NOTHING_CONDITION;
@@ -346,16 +353,16 @@ export class InsightsRoutingBaseService {
parentId: options.orgId,
select: { id: true },
});
if (!childTeamOfOrg) {
if (options.orgId && !childTeamOfOrg) {
return NOTHING_CONDITION;
}
return Prisma.sql`"formTeamId" = ${options.teamId}`;
}
private async isOrgOwnerOrAdmin(userId: number, orgId: number): Promise<boolean> {
// Check if the user is an owner or admin of the organization
const membership = await MembershipRepository.findUniqueByUserIdAndTeamId({ userId, teamId: orgId });
private async isOwnerOrAdmin(userId: number, targetId: number): Promise<boolean> {
// Check if the user is an owner or admin of the organization or team
const membership = await MembershipRepository.findUniqueByUserIdAndTeamId({ userId, teamId: targetId });
return Boolean(
membership &&
membership.accepted &&