From 95307164b665aa2c7d6610e5d5f53a86ea6e7d2a Mon Sep 17 00:00:00 2001 From: August Andersen Date: Tue, 17 Sep 2024 16:34:36 +0200 Subject: [PATCH 1/2] Made endpoint for fetching gateways to map, since there has to be no limit (and only select what's needed) --- .../chirpstack-gateway.controller.ts | 8 ++++ .../chirpstack/chirpstack-gateway.service.ts | 41 ++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/controllers/admin-controller/chirpstack/chirpstack-gateway.controller.ts b/src/controllers/admin-controller/chirpstack/chirpstack-gateway.controller.ts index b428374f..1625bfde 100644 --- a/src/controllers/admin-controller/chirpstack/chirpstack-gateway.controller.ts +++ b/src/controllers/admin-controller/chirpstack/chirpstack-gateway.controller.ts @@ -75,6 +75,14 @@ export class ChirpstackGatewayController { return await this.chirpstackGatewayService.getWithPaginationAndSorting(query, query.organizationId); } + @Get("getAllForMaps") + @ApiProduces("application/json") + @ApiOperation({ summary: "List all Chirpstack gateways for maps" }) + @Read() + async getAllForMaps(@Query() query?: ListAllGatewaysDto): Promise { + return await this.chirpstackGatewayService.getForMaps(query.organizationId); + } + @Get(":gatewayId") @ApiProduces("application/json") @ApiOperation({ summary: "Single Chirpstack gateway" }) diff --git a/src/services/chirpstack/chirpstack-gateway.service.ts b/src/services/chirpstack/chirpstack-gateway.service.ts index b08fa880..abe795a6 100644 --- a/src/services/chirpstack/chirpstack-gateway.service.ts +++ b/src/services/chirpstack/chirpstack-gateway.service.ts @@ -150,7 +150,7 @@ export class ChirpstackGatewayService extends GenericChirpstackConfigurationServ const gateways = await query.getMany(); return { - resultList: gateways.map(this.mapGatewayToResponseDto), + resultList: gateways.map(gateway => this.mapGatewayToResponseDto(gateway)), totalCount: gateways.length, }; } @@ -177,7 +177,33 @@ export class ChirpstackGatewayService extends GenericChirpstackConfigurationServ const [gateways, count] = await query.getManyAndCount(); return { - resultList: gateways.map(this.mapGatewayToResponseDto), + resultList: gateways.map(gateway => this.mapGatewayToResponseDto(gateway)), + totalCount: count, + }; + } + + public async getForMaps(organizationId?: number): Promise { + let query = this.gatewayRepository + .createQueryBuilder("gateway") + .innerJoinAndSelect("gateway.organization", "organization") + .select([ + "gateway.location", + "gateway.name", + "gateway.lastSeenAt", + "gateway.id", + "gateway.gatewayId", + "organization.name", + "organization.id", + ]); + + if (organizationId) { + query = query.where('"organizationId" = :organizationId', { organizationId }); + } + + const [gateways, count] = await query.getManyAndCount(); + + return { + resultList: gateways.map(gateway => this.mapGatewayToResponseDto(gateway, true)), totalCount: count, }; } @@ -461,7 +487,7 @@ export class ChirpstackGatewayService extends GenericChirpstackConfigurationServ return gateway; } - private mapGatewayToResponseDto(gateway: DbGateway): GatewayResponseDto { + private mapGatewayToResponseDto(gateway: DbGateway, fromMap = false): GatewayResponseDto { const responseDto = gateway as unknown as GatewayResponseDto; responseDto.organizationId = gateway.organization.id; responseDto.organizationName = gateway.organization.name; @@ -469,12 +495,17 @@ export class ChirpstackGatewayService extends GenericChirpstackConfigurationServ const commonLocation = new CommonLocationDto(); commonLocation.latitude = gateway.location.coordinates[1]; commonLocation.longitude = gateway.location.coordinates[0]; - commonLocation.altitude = gateway.altitude; - responseDto.tags = JSON.parse(gateway.tags); + + if (!fromMap) { + commonLocation.altitude = gateway.altitude; + responseDto.tags = JSON.parse(gateway.tags); + } + responseDto.location = commonLocation; return responseDto; } + async getAllGatewaysFromChirpstack(): Promise { const limit = 1000; const listReq = new ListGatewaysRequest(); From 59adbbac6d713a1daa8facfb83570ba72d35de2a Mon Sep 17 00:00:00 2001 From: August Andersen Date: Wed, 18 Sep 2024 09:39:20 +0200 Subject: [PATCH 2/2] PR changes --- src/services/chirpstack/chirpstack-gateway.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/chirpstack/chirpstack-gateway.service.ts b/src/services/chirpstack/chirpstack-gateway.service.ts index abe795a6..3f4ca003 100644 --- a/src/services/chirpstack/chirpstack-gateway.service.ts +++ b/src/services/chirpstack/chirpstack-gateway.service.ts @@ -487,7 +487,7 @@ export class ChirpstackGatewayService extends GenericChirpstackConfigurationServ return gateway; } - private mapGatewayToResponseDto(gateway: DbGateway, fromMap = false): GatewayResponseDto { + private mapGatewayToResponseDto(gateway: DbGateway, forMap = false): GatewayResponseDto { const responseDto = gateway as unknown as GatewayResponseDto; responseDto.organizationId = gateway.organization.id; responseDto.organizationName = gateway.organization.name; @@ -496,7 +496,7 @@ export class ChirpstackGatewayService extends GenericChirpstackConfigurationServ commonLocation.latitude = gateway.location.coordinates[1]; commonLocation.longitude = gateway.location.coordinates[0]; - if (!fromMap) { + if (!forMap) { commonLocation.altitude = gateway.altitude; responseDto.tags = JSON.parse(gateway.tags); }