Skip to content

Commit

Permalink
Merge branch 'feature/include-airports-in-config-endpoint' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dotFionn committed Oct 4, 2023
2 parents 0e93c04 + e2fea1e commit 8024865
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/backend/controllers/meta.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fs from 'fs';

import { Request, Response } from 'express';
import { NextFunction, Request, Response } from 'express';

import config from '../config';
import airportService from '../services/airport.service';

const packageString = fs.readFileSync('./package.json');
let versionResponse = {
Expand All @@ -15,7 +16,7 @@ let versionResponse = {
if (packageString) {
const packageJson = JSON.parse(packageString.toString());

// eslint-disable-next-line @typescript-eslint/naming-convention
// eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/no-unused-vars
const [version, major, minor, patch, _, prerelease] =
/(\d).(\d).(\d)(-(.*))?/gi.exec(packageJson.version) as string[];

Expand All @@ -36,6 +37,20 @@ export function getPluginConfig(req: Request, res: Response) {
res.json(config().pluginSettings);
}

async function getExtendedPluginConfig(req: Request, res: Response, next: NextFunction) {
try {
const airports = await airportService.getAllSupportedAirportsOrEmptyArray();

res.json({
version: versionResponse,
config: config().pluginSettings,
supportedAirports: airports,
});
} catch (e) {
next(e);
}
}

export function getFrontendConfig(req: Request, res: Response) {
res.json(config().frontendSettings);
}
Expand All @@ -44,4 +59,5 @@ export default {
getVersion,
getPluginConfig,
getFrontendConfig,
getExtendedPluginConfig,
};
2 changes: 1 addition & 1 deletion src/backend/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ router.use(requestloggerUtils);

router.get('/version', metaController.getVersion);
router.get('/config', metaController.getPluginConfig);
router.get('/config/plugin', metaController.getPluginConfig);
router.get('/config/plugin', metaController.getExtendedPluginConfig);
router.get('/config/frontend', metaController.getFrontendConfig);

router.get('/datafeed', miscController.getDataFeed);
Expand Down
12 changes: 12 additions & 0 deletions src/backend/services/airport.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ export async function determineRunway(pilot: PilotDocument): Promise<string> {
}
}

export async function getAllSupportedAirportsOrEmptyArray(): Promise<string[]> {
try {
const airports = await getAllAirports();

return airports.map(a => a.icao);
} catch (error) {
return [];
}
}

export default {
getAllAirports,
getAirport,
Expand All @@ -208,4 +218,6 @@ export default {
determineTaxizone,
determineRunway,
getCapacity,

getAllSupportedAirportsOrEmptyArray,
};

0 comments on commit 8024865

Please sign in to comment.