@@ -30,18 +30,21 @@ import { ComposeAuthGuard } from "@auth/compose-auth.guard";
3030import { ApplicationAdmin , Read } from "@auth/roles.decorator" ;
3131import { RolesGuard } from "@auth/roles.guard" ;
3232import { ApiAuth } from "@auth/swagger-auth-decorator" ;
33+ import { ApplicationDashboardResponseDto } from "@dto/applications-dashboard-responses" ;
3334import { CreateApplicationDto } from "@dto/create-application.dto" ;
3435import { DeleteResponseDto } from "@dto/delete-application-response.dto" ;
3536import { ListAllApplicationsResponseDto } from "@dto/list-all-applications-response.dto" ;
3637import { ListAllApplicationsDto } from "@dto/list-all-applications.dto" ;
3738import { ListAllEntitiesDto } from "@dto/list-all-entities.dto" ;
3839import { ListAllIoTDevicesResponseDto } from "@dto/list-all-iot-devices-response.dto" ;
3940import { IoTDevicesListToMapResponseDto } from "@dto/list-all-iot-devices-to-map-response.dto" ;
41+ import { ListAllIotDevicesDto } from "@dto/list-all-iot-devices.dto" ;
4042import { UpdateApplicationOrganizationDto } from "@dto/update-application-organization.dto" ;
4143import { UpdateApplicationDto } from "@dto/update-application.dto" ;
4244import { Application } from "@entities/application.entity" ;
4345import { ActionType } from "@entities/audit-log-entry" ;
4446import { AuthenticatedRequest } from "@entities/dto/internal/authenticated-request" ;
47+ import { IoTDevice } from "@entities/iot-device.entity" ;
4548import { ErrorCodes } from "@enum/error-codes.enum" ;
4649import {
4750 ApplicationAccessScope ,
@@ -60,10 +63,10 @@ import { ApplicationService } from "@services/device-management/application.serv
6063@ApiForbiddenResponse ( )
6164@ApiUnauthorizedResponse ( )
6265export class ApplicationController {
63- constructor ( private applicationService : ApplicationService ) { }
64-
6566 private readonly logger = new Logger ( ApplicationController . name ) ;
6667
68+ constructor ( private applicationService : ApplicationService ) { }
69+
6770 @Read ( )
6871 @Get ( )
6972 @ApiProduces ( "application/json" )
@@ -78,15 +81,62 @@ export class ApplicationController {
7881 @Query ( ) query ?: ListAllApplicationsDto
7982 ) : Promise < ListAllApplicationsResponseDto > {
8083 if ( req . user . permissions . isGlobalAdmin ) {
81- return this . applicationService . findAndCountWithPagination (
82- query ,
83- query . organizationId ? [ + query . organizationId ] : null
84- ) ;
84+ return this . applicationService . findAndCountInList ( query ) ;
8585 }
8686
8787 return await this . getApplicationsForNonGlobalAdmin ( req , query ) ;
8888 }
8989
90+ @Read ( )
91+ @Get ( ":id/filter-information" )
92+ @ApiProduces ( "application/json" )
93+ @ApiOperation ( { summary : "returns filter information for application" } )
94+ @ApiNotFoundResponse ( )
95+ async findFilterInformation (
96+ @Req ( ) req : AuthenticatedRequest ,
97+ @Param ( "id" , new ParseIntPipe ( ) ) id : number
98+ ) : Promise < string [ ] > {
99+ try {
100+ const allOrgs = req . user . permissions . getAllOrganizationsWithUserAdmin ( ) ;
101+
102+ return await this . applicationService . getFilterInformationInOrganization (
103+ allOrgs ,
104+ id ,
105+ req . user . permissions . isGlobalAdmin
106+ ) ;
107+ } catch ( err ) {
108+ throw new NotFoundException ( ErrorCodes . IdDoesNotExists ) ;
109+ }
110+ }
111+
112+ @Read ( )
113+ @Get ( ":id/application-dashboard-data" )
114+ @ApiProduces ( "application/json" )
115+ @ApiOperation ( { summary : "returns applications dashboard data" } )
116+ @ApiNotFoundResponse ( )
117+ async countApplicationWithError (
118+ @Req ( ) req : AuthenticatedRequest ,
119+ @Param ( "id" , new ParseIntPipe ( ) ) organizationId : number
120+ ) : Promise < ApplicationDashboardResponseDto > {
121+ try {
122+ checkIfUserHasAccessToOrganization ( req , organizationId , OrganizationAccessScope . ApplicationRead ) ;
123+ const whitelist = req . user . permissions . getAllApplicationsWithAtLeastRead ( ) ;
124+
125+ return {
126+ ...( await this . applicationService . countApplicationsWithError (
127+ organizationId ,
128+ req . user . permissions . isGlobalAdmin ? "admin" : whitelist
129+ ) ) ,
130+ totalDevices : await this . applicationService . countAllDevices (
131+ organizationId ,
132+ req . user . permissions . isGlobalAdmin ? "admin" : whitelist
133+ ) ,
134+ } ;
135+ } catch ( err ) {
136+ throw new NotFoundException ( ErrorCodes . IdDoesNotExists ) ;
137+ }
138+ }
139+
90140 @Read ( )
91141 @Get ( ":id" )
92142 @ApiOperation ( { summary : "Find one Application by id" } )
@@ -119,6 +169,27 @@ export class ApplicationController {
119169 }
120170 }
121171
172+ @Read ( )
173+ @Get ( ":id/iot-devices-org" )
174+ @ApiOperation ( { summary : "Find the IoTDevice of an organization" } )
175+ @ApiNotFoundResponse ( )
176+ async findIoTDevicesForOrganization (
177+ @Req ( ) req : AuthenticatedRequest ,
178+ @Param ( "id" , new ParseIntPipe ( ) ) organizationId : number ,
179+ @Query ( ) query ?: ListAllIotDevicesDto
180+ ) : Promise < IoTDevice [ ] > {
181+ try {
182+ const allOrgs = req . user . permissions . getAllOrganizationsWithUserAdmin ( ) ;
183+ return await this . applicationService . getAllDevices (
184+ organizationId ,
185+ query ,
186+ req . user . permissions . isGlobalAdmin ? "admin" : allOrgs
187+ ) ;
188+ } catch ( err ) {
189+ throw new NotFoundException ( ErrorCodes . IdDoesNotExists ) ;
190+ }
191+ }
192+
122193 @Read ( )
123194 @Get ( ":id/iot-devices-map" )
124195 @ApiOperation ( { summary : "Find the IoTDevices of an Application" } )
@@ -257,10 +328,10 @@ export class ApplicationController {
257328 // User admins have access to all applications in the organization
258329 const allFromOrg = req . user . permissions . getAllOrganizationsWithUserAdmin ( ) ;
259330 if ( allFromOrg . some ( x => x === query ?. organizationId ) ) {
260- return await this . applicationService . findAndCountWithPagination ( query , [ query . organizationId ] ) ;
331+ return await this . applicationService . findAndCountInList ( query , null ) ;
261332 }
262333
263334 const allowedApplications = req . user . permissions . getAllApplicationsWithAtLeastRead ( ) ;
264- return await this . applicationService . findAndCountInList ( query , allowedApplications , [ query . organizationId ] ) ;
335+ return await this . applicationService . findAndCountInList ( query , allowedApplications ) ;
265336 }
266337}
0 commit comments