@@ -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 ,
@@ -78,15 +81,61 @@ 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 ( ) ) id : number
120+ ) : Promise < ApplicationDashboardResponseDto > {
121+ try {
122+ const allOrgs = req . user . permissions . getAllOrganizationsWithUserAdmin ( ) ;
123+
124+ return {
125+ ...( await this . applicationService . countApplicationsWithError (
126+ id ,
127+ req . user . permissions . isGlobalAdmin ? "admin" : allOrgs
128+ ) ) ,
129+ totalDevices : await this . applicationService . countAllDevices (
130+ id ,
131+ req . user . permissions . isGlobalAdmin ? "admin" : allOrgs
132+ ) ,
133+ } ;
134+ } catch ( err ) {
135+ throw new NotFoundException ( ErrorCodes . IdDoesNotExists ) ;
136+ }
137+ }
138+
90139 @Read ( )
91140 @Get ( ":id" )
92141 @ApiOperation ( { summary : "Find one Application by id" } )
@@ -119,6 +168,27 @@ export class ApplicationController {
119168 }
120169 }
121170
171+ @Read ( )
172+ @Get ( ":id/iot-devices-org" )
173+ @ApiOperation ( { summary : "Find the IoTDevice of an organization" } )
174+ @ApiNotFoundResponse ( )
175+ async findIoTDevicesForOrganization (
176+ @Req ( ) req : AuthenticatedRequest ,
177+ @Param ( "id" , new ParseIntPipe ( ) ) organizationId : number ,
178+ @Query ( ) query ?: ListAllIotDevicesDto
179+ ) : Promise < IoTDevice [ ] > {
180+ try {
181+ const allOrgs = req . user . permissions . getAllOrganizationsWithUserAdmin ( ) ;
182+ return await this . applicationService . getAllDevices (
183+ organizationId ,
184+ query ,
185+ req . user . permissions . isGlobalAdmin ? "admin" : allOrgs
186+ ) ;
187+ } catch ( err ) {
188+ throw new NotFoundException ( ErrorCodes . IdDoesNotExists ) ;
189+ }
190+ }
191+
122192 @Read ( )
123193 @Get ( ":id/iot-devices-map" )
124194 @ApiOperation ( { summary : "Find the IoTDevices of an Application" } )
@@ -257,10 +327,10 @@ export class ApplicationController {
257327 // User admins have access to all applications in the organization
258328 const allFromOrg = req . user . permissions . getAllOrganizationsWithUserAdmin ( ) ;
259329 if ( allFromOrg . some ( x => x === query ?. organizationId ) ) {
260- return await this . applicationService . findAndCountWithPagination ( query , [ query . organizationId ] ) ;
330+ return await this . applicationService . findAndCountInList ( query , null ) ;
261331 }
262332
263333 const allowedApplications = req . user . permissions . getAllApplicationsWithAtLeastRead ( ) ;
264- return await this . applicationService . findAndCountInList ( query , allowedApplications , [ query . organizationId ] ) ;
334+ return await this . applicationService . findAndCountInList ( query , allowedApplications ) ;
265335 }
266336}
0 commit comments