11// src/Modules/GoTransit/index.ts
2- import { plainToInstance } from 'class-transformer' ;
2+ import { plainToInstance , TransformPlainToInstance } from 'class-transformer' ;
33import got , { OptionsOfJSONResponseBody } from 'got' ;
4+ import { Service } from 'typedi' ;
45import { CONFIG } from '../../Library/Config' ;
56import { logger , LogMode } from '../../Library/Logger' ;
6- import { GoTransitStop , GoTransitStopType } from './Stop' ;
7+ import { GoTransitStop } from './Stop' ;
78import { GoTransitTrainTrip } from './TrainTrip' ;
89import { GoTransitUnionDepartureTrip } from './UnionDeparture' ;
910
@@ -21,10 +22,11 @@ interface APIMetadata {
2122 ErrorMessage : string ;
2223}
2324
24- interface APIResponse {
25+ export interface APIResponse {
2526 Metadata : APIMetadata ;
2627}
2728
29+ @Service ( )
2830export class GoTransit {
2931 private config : GoTransitConfig = {
3032 apiToken : CONFIG . token ,
@@ -45,7 +47,7 @@ export class GoTransit {
4547 } ,
4648 } ) ;
4749
48- private async makeRequest < ResponseType extends APIResponse > (
50+ public async makeRequest < ResponseType extends APIResponse > (
4951 url : string ,
5052 options ?: OptionsOfJSONResponseBody ,
5153 ) : Promise < ResponseType > {
@@ -66,7 +68,7 @@ export class GoTransit {
6668 /**
6769 * Gets all the trains soon arriving at Union and the platform allocation
6870 * if provided/same as the departure board/go tracker.
69- *
71+ *
7072 * @returns array of GoTransitUnionDepartureTrip
7173 */
7274 public async unionDepartures ( ) : Promise < GoTransitUnionDepartureTrip [ ] > {
@@ -80,7 +82,6 @@ export class GoTransit {
8082 ) ;
8183 }
8284
83-
8485 /**
8586 * Function to get all active trains within the Go Transit network.
8687 *
@@ -96,15 +97,16 @@ export class GoTransit {
9697
9798 /**
9899 * Get all Go Transit Stops within the network
99- *
100- * @returns Array of all Go Transit Bus Stops,
100+ *
101+ * @returns Array of all Go Transit Bus Stops,
101102 * Bus Terminals, Bus & Train Stations, and Park & Ride Stops
102103 */
104+ @TransformPlainToInstance ( GoTransitStop )
103105 public async getAllStops ( ) : Promise < GoTransitStop [ ] > {
104106 const response = await this . makeRequest <
105107 APIResponse & { Stations : { Station : GoTransitStop [ ] } }
106108 > ( 'Stop/All' ) ;
107109
108- return plainToInstance ( GoTransitStop , response . Stations . Station ) ;
110+ return response . Stations . Station ;
109111 }
110112}
0 commit comments