diff --git a/src/controllers/admin-controller/chirpstack/network-server.controller.ts b/src/controllers/admin-controller/chirpstack/network-server.controller.ts new file mode 100644 index 00000000..4016f3a8 --- /dev/null +++ b/src/controllers/admin-controller/chirpstack/network-server.controller.ts @@ -0,0 +1,36 @@ +import { ComposeAuthGuard } from '@auth/compose-auth.guard'; +import { + Controller, + Get, + Logger, + UseGuards, +} from "@nestjs/common"; +import { + ApiBearerAuth, + ApiOperation, + ApiProduces, + ApiTags, +} from "@nestjs/swagger"; + +import { Read, ApplicationAdmin } from "@auth/roles.decorator"; +import { RolesGuard } from "@auth/roles.guard"; +import { ChirpstackSetupNetworkServerService } from "@services/chirpstack/network-server.service"; +import { ListAllAdrAlgorithmsResponseDto } from "@dto/chirpstack/list-all-adr-algorithms-response.dto"; + +@ApiTags("Chirpstack") +@Controller("chirpstack/network-server") +@UseGuards(ComposeAuthGuard, RolesGuard) +@ApiBearerAuth() +@ApplicationAdmin() +export class NetworkServerController { + constructor(private networkServerService: ChirpstackSetupNetworkServerService) {} + private readonly logger = new Logger(NetworkServerController.name); + + @Get("adr-algorithms") + @ApiProduces("application/json") + @ApiOperation({ summary: "Find all ADR algorithms for the default network server" }) + @Read() + async getAllAdrAlgorithms(): Promise { + return await this.networkServerService.getAdrAlgorithmsForDefaultNetworkServer(); + } +} diff --git a/src/entities/dto/chirpstack/adr-algorithm.dto.ts b/src/entities/dto/chirpstack/adr-algorithm.dto.ts new file mode 100644 index 00000000..b0cbbd0d --- /dev/null +++ b/src/entities/dto/chirpstack/adr-algorithm.dto.ts @@ -0,0 +1,17 @@ +import { ApiProperty } from "@nestjs/swagger"; +import { + IsString, + Length, +} from "class-validator"; + +export class AdrAlgorithmDto { + @ApiProperty({ required: true }) + @IsString() + @Length(1, 1024) + id: string; + + @ApiProperty({ required: true }) + @IsString() + @Length(1, 1024) + name: string; +} diff --git a/src/entities/dto/chirpstack/device-profile.dto.ts b/src/entities/dto/chirpstack/device-profile.dto.ts index 1301aedb..51df9b1c 100644 --- a/src/entities/dto/chirpstack/device-profile.dto.ts +++ b/src/entities/dto/chirpstack/device-profile.dto.ts @@ -27,6 +27,10 @@ export class DeviceProfileDto { @ApiProperty({ required: true }) regParamsRevision: "A" | "B"; + @ApiProperty({ required: false }) + @IsString() + adrAlgorithmID?: string; + @ApiProperty({ required: false }) @ValidateIf((o: DeviceProfileDto) => o.supportsClassB) @Min(0) diff --git a/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts b/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts new file mode 100644 index 00000000..6ba12710 --- /dev/null +++ b/src/entities/dto/chirpstack/list-all-adr-algorithms-response.dto.ts @@ -0,0 +1,5 @@ +import { AdrAlgorithmDto } from "@dto/chirpstack/adr-algorithm.dto"; + +export class ListAllAdrAlgorithmsResponseDto { + adrAlgorithms: AdrAlgorithmDto[]; +} diff --git a/src/modules/device-integrations/chirpstack-administration.module.ts b/src/modules/device-integrations/chirpstack-administration.module.ts index bc1fc45c..f0bf743d 100644 --- a/src/modules/device-integrations/chirpstack-administration.module.ts +++ b/src/modules/device-integrations/chirpstack-administration.module.ts @@ -10,12 +10,14 @@ import { DeviceProfileService } from "@services/chirpstack/device-profile.servic import { GenericChirpstackConfigurationService } from "@services/chirpstack/generic-chirpstack-configuration.service"; import { ChirpstackSetupNetworkServerService } from "@services/chirpstack/network-server.service"; import { ServiceProfileService } from "@services/chirpstack/service-profile.service"; +import { NetworkServerController } from "@admin-controller/chirpstack/network-server.controller"; @Module({ controllers: [ ChirpstackGatewayController, ServiceProfileController, DeviceProfileController, + NetworkServerController ], imports: [HttpModule, ConfigModule.forRoot({ load: [configuration] })], providers: [ diff --git a/src/services/chirpstack/network-server.service.ts b/src/services/chirpstack/network-server.service.ts index 8a50325f..02cce160 100644 --- a/src/services/chirpstack/network-server.service.ts +++ b/src/services/chirpstack/network-server.service.ts @@ -6,6 +6,7 @@ import { ListAllNetworkServerResponseDto } from "@dto/chirpstack/list-all-networ import { NetworkServerDto } from "@dto/chirpstack/network-server.dto"; import { GenericChirpstackConfigurationService } from "./generic-chirpstack-configuration.service"; +import { ListAllAdrAlgorithmsResponseDto } from "@dto/chirpstack/list-all-adr-algorithms-response.dto"; @Injectable() export class ChirpstackSetupNetworkServerService @@ -68,4 +69,9 @@ export class ChirpstackSetupNetworkServerService return createNetworkServerDto; } + + public async getAdrAlgorithmsForDefaultNetworkServer(): Promise { + const networkServerId = await this.getDefaultNetworkServerId(); + return await this.get(`network-servers/${networkServerId}/adr-algorithms`); + } }