Skip to content

Commit 9d78549

Browse files
Fix application fetch (#278)
1 parent dc7fc73 commit 9d78549

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/controllers/admin-controller/application.controller.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ import { ApplicationService } from "@services/device-management/application.serv
6363
@ApiForbiddenResponse()
6464
@ApiUnauthorizedResponse()
6565
export class ApplicationController {
66-
constructor(private applicationService: ApplicationService) {}
67-
6866
private readonly logger = new Logger(ApplicationController.name);
6967

68+
constructor(private applicationService: ApplicationService) {}
69+
7070
@Read()
7171
@Get()
7272
@ApiProduces("application/json")
@@ -116,19 +116,20 @@ export class ApplicationController {
116116
@ApiNotFoundResponse()
117117
async countApplicationWithError(
118118
@Req() req: AuthenticatedRequest,
119-
@Param("id", new ParseIntPipe()) id: number
119+
@Param("id", new ParseIntPipe()) organizationId: number
120120
): Promise<ApplicationDashboardResponseDto> {
121121
try {
122-
const allOrgs = req.user.permissions.getAllOrganizationsWithUserAdmin();
122+
checkIfUserHasAccessToOrganization(req, organizationId, OrganizationAccessScope.ApplicationRead);
123+
const whitelist = req.user.permissions.getAllApplicationsWithAtLeastRead();
123124

124125
return {
125126
...(await this.applicationService.countApplicationsWithError(
126-
id,
127-
req.user.permissions.isGlobalAdmin ? "admin" : allOrgs
127+
organizationId,
128+
req.user.permissions.isGlobalAdmin ? "admin" : whitelist
128129
)),
129130
totalDevices: await this.applicationService.countAllDevices(
130-
id,
131-
req.user.permissions.isGlobalAdmin ? "admin" : allOrgs
131+
organizationId,
132+
req.user.permissions.isGlobalAdmin ? "admin" : whitelist
132133
),
133134
};
134135
} catch (err) {

src/services/device-management/application.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ export class ApplicationService {
5656

5757
async countApplicationsWithError(
5858
organizationId: number,
59-
whitelist?: number[] | "admin"
59+
whitelist: number[] | "admin"
6060
): Promise<ApplicationsWithErrorsResponseDto> {
6161
const queryBuilder = this.applicationRepository
6262
.createQueryBuilder("app")
6363
.leftJoin("app.iotDevices", "device")
6464
.leftJoin("app.belongsTo", "organization")
6565
.leftJoin("device.latestReceivedMessage", "latestMessage")
6666
.leftJoin("app.dataTargets", "dataTargets")
67-
.andWhere("app.belongsToId = :organizationId", { organizationId: organizationId });
67+
.where("app.belongsToId = :organizationId", { organizationId: organizationId });
6868

6969
if (whitelist !== "admin" && whitelist.length > 0) {
70-
queryBuilder.where("app.id IN (:...whitelist)", { whitelist });
70+
queryBuilder.andWhere("app.id IN (:...whitelist)", { whitelist });
7171
}
7272

7373
try {
@@ -90,7 +90,7 @@ export class ApplicationService {
9090
}
9191
}
9292

93-
async countAllDevices(organizationId: number, whitelist?: number[] | "admin"): Promise<number> {
93+
async countAllDevices(organizationId: number, whitelist: number[] | "admin"): Promise<number> {
9494
const queryBuilder = this.applicationRepository
9595
.createQueryBuilder("app")
9696
.leftJoinAndSelect("app.iotDevices", "device")
@@ -175,7 +175,7 @@ export class ApplicationService {
175175
.andWhere("app.belongsToId = :organizationId", { organizationId: query.organizationId });
176176

177177
if (whitelist && whitelist.length > 0) {
178-
queryBuilder.where("app.id IN (:...whitelist)", { whitelist });
178+
queryBuilder.andWhere("app.id IN (:...whitelist)", { whitelist });
179179
}
180180

181181
if (query.status) {

0 commit comments

Comments
 (0)