Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -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<ListAllAdrAlgorithmsResponseDto> {
return await this.networkServerService.getAdrAlgorithmsForDefaultNetworkServer();
}
}
17 changes: 17 additions & 0 deletions src/entities/dto/chirpstack/adr-algorithm.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 4 additions & 0 deletions src/entities/dto/chirpstack/device-profile.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AdrAlgorithmDto } from "@dto/chirpstack/adr-algorithm.dto";

export class ListAllAdrAlgorithmsResponseDto {
adrAlgorithms: AdrAlgorithmDto[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
6 changes: 6 additions & 0 deletions src/services/chirpstack/network-server.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,4 +69,9 @@ export class ChirpstackSetupNetworkServerService

return createNetworkServerDto;
}

public async getAdrAlgorithmsForDefaultNetworkServer(): Promise<ListAllAdrAlgorithmsResponseDto> {
const networkServerId = await this.getDefaultNetworkServerId();
return await this.get(`network-servers/${networkServerId}/adr-algorithms`);
}
}