Add StationDataModule, implementing getNearestStations & a Geohash generator method
All checks were successful
Publish Package / build-and-publish (push) Successful in 6s
All checks were successful
Publish Package / build-and-publish (push) Successful in 6s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { ApiPisObject } from '@owlboard/api-schema-types';
|
||||
import type { BaseClient, ApiResult } from '../lib/base.js';
|
||||
import { IsValidCrs, IsValidTiploc, IsValidPis } from '../lib/validation.js';
|
||||
import { IsValidCrs, IsValidPis } from '../lib/validation.js';
|
||||
import { ValidationError } from '../lib/errors.js';
|
||||
|
||||
export class PisModule {
|
||||
|
||||
37
src/modules/stationData.ts
Normal file
37
src/modules/stationData.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { ApiStationsNearestStations } from '@owlboard/api-schema-types';
|
||||
import type { BaseClient, ApiResult } from '../lib/base.js';
|
||||
import { IsValidGeoHash } from '../lib/validation.js';
|
||||
import { ValidationError } from '../lib/errors.js';
|
||||
import Geohash from 'latlon-geohash';
|
||||
|
||||
export class StationDataModule {
|
||||
constructor(private client: BaseClient) {}
|
||||
|
||||
/**
|
||||
* Generates a 6-char Geohash for the given co-ordinates
|
||||
* @param lt Latitude
|
||||
* @param ln Longitude
|
||||
* @returns Geohash as string
|
||||
*/
|
||||
static generateGeohash(lt: number, ln: number): string {
|
||||
return Geohash.encode(lt, ln, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param geohash Geohash as string (up to six characters), generate using this.generateGeohash()
|
||||
* @returns Nearest Stations API Response (CRS, Name)
|
||||
*/
|
||||
async getNearestStations(geohash: string): Promise<ApiResult<ApiStationsNearestStations.StationsNearestStations[]>> {
|
||||
if (!IsValidGeoHash(geohash)) {
|
||||
throw new ValidationError("hash", "Invalid Geohash requested");
|
||||
}
|
||||
|
||||
const path = `/stationData/nearest/${geohash}`;
|
||||
return this.client.request<ApiStationsNearestStations.StationsNearestStations[]>(path, {
|
||||
method: 'GET',
|
||||
})
|
||||
}
|
||||
|
||||
// getStationSate(crs: string){}
|
||||
}
|
||||
Reference in New Issue
Block a user