Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/IoT-1585 limit on gateways map #259

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<ListAllGatewaysResponseDto> {
return await this.chirpstackGatewayService.getForMaps(query.organizationId);
}

@Get(":gatewayId")
@ApiProduces("application/json")
@ApiOperation({ summary: "Single Chirpstack gateway" })
Expand Down
41 changes: 36 additions & 5 deletions src/services/chirpstack/chirpstack-gateway.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand All @@ -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<ListAllGatewaysResponseDto> {
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,
};
}
Expand Down Expand Up @@ -461,20 +487,25 @@ 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;

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<ListAllChirpstackGatewaysResponseDto> {
const limit = 1000;
const listReq = new ListGatewaysRequest();
Expand Down
Loading