Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 9 additions & 8 deletions src/controllers/admin-controller/application.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ import { ApplicationService } from "@services/device-management/application.serv
@ApiForbiddenResponse()
@ApiUnauthorizedResponse()
export class ApplicationController {
constructor(private applicationService: ApplicationService) {}

private readonly logger = new Logger(ApplicationController.name);

constructor(private applicationService: ApplicationService) {}

@Read()
@Get()
@ApiProduces("application/json")
Expand Down Expand Up @@ -116,19 +116,20 @@ export class ApplicationController {
@ApiNotFoundResponse()
async countApplicationWithError(
@Req() req: AuthenticatedRequest,
@Param("id", new ParseIntPipe()) id: number
@Param("id", new ParseIntPipe()) organizationId: number
): Promise<ApplicationDashboardResponseDto> {
try {
const allOrgs = req.user.permissions.getAllOrganizationsWithUserAdmin();
checkIfUserHasAccessToOrganization(req, organizationId, OrganizationAccessScope.ApplicationRead);
const whitelist = req.user.permissions.getAllApplicationsWithAtLeastRead();

return {
...(await this.applicationService.countApplicationsWithError(
id,
req.user.permissions.isGlobalAdmin ? "admin" : allOrgs
organizationId,
req.user.permissions.isGlobalAdmin ? "admin" : whitelist
)),
totalDevices: await this.applicationService.countAllDevices(
id,
req.user.permissions.isGlobalAdmin ? "admin" : allOrgs
organizationId,
req.user.permissions.isGlobalAdmin ? "admin" : whitelist
),
};
} catch (err) {
Expand Down
10 changes: 5 additions & 5 deletions src/services/device-management/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ export class ApplicationService {

async countApplicationsWithError(
organizationId: number,
whitelist?: number[] | "admin"
whitelist: number[] | "admin"
): Promise<ApplicationsWithErrorsResponseDto> {
const queryBuilder = this.applicationRepository
.createQueryBuilder("app")
.leftJoin("app.iotDevices", "device")
.leftJoin("app.belongsTo", "organization")
.leftJoin("device.latestReceivedMessage", "latestMessage")
.leftJoin("app.dataTargets", "dataTargets")
.andWhere("app.belongsToId = :organizationId", { organizationId: organizationId });
.where("app.belongsToId = :organizationId", { organizationId: organizationId });

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

try {
Expand All @@ -90,7 +90,7 @@ export class ApplicationService {
}
}

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

if (whitelist && whitelist.length > 0) {
queryBuilder.where("app.id IN (:...whitelist)", { whitelist });
queryBuilder.andWhere("app.id IN (:...whitelist)", { whitelist });
}

if (query.status) {
Expand Down