File tree Expand file tree Collapse file tree 5 files changed +126
-2
lines changed Expand file tree Collapse file tree 5 files changed +126
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { ImportModule } from "src/modules/import/import.module";
14
14
import { LoggerModule } from "src/modules/logger/logger.module" ;
15
15
import { PlatformModule } from "src/modules/platform/platform.module" ;
16
16
import { PrismaModule } from "src/modules/prisma/prisma.module" ;
17
+ import { RouteModule } from "src/modules/route/route.module" ;
17
18
import { StatusModule } from "src/modules/status/status.module" ;
18
19
import { StopModule } from "src/modules/stop/stop.module" ;
19
20
@@ -27,6 +28,7 @@ import { StopModule } from "src/modules/stop/stop.module";
27
28
LoggerModule ,
28
29
StatusModule ,
29
30
GtfsModule ,
31
+ RouteModule ,
30
32
ConfigModule . forRoot ( configModuleConfig ) ,
31
33
ScheduleModule . forRoot ( ) ,
32
34
CacheModule . registerAsync ( cacheModuleConfig ) ,
Original file line number Diff line number Diff line change @@ -8,11 +8,19 @@ export class GtfsController implements OnModuleInit {
8
8
constructor ( private readonly gtfsService : GtfsService ) { }
9
9
10
10
async onModuleInit ( ) : Promise < void > {
11
- await this . gtfsService . syncGtfsData ( ) ;
11
+ try {
12
+ this . gtfsService . syncGtfsData ( ) ;
13
+ } catch ( error ) {
14
+ console . error ( error ) ;
15
+ }
12
16
}
13
17
14
18
@Cron ( CronExpression . EVERY_7_HOURS )
15
19
async cronSyncStops ( ) : Promise < void > {
16
- await this . gtfsService . syncGtfsData ( ) ;
20
+ try {
21
+ await this . gtfsService . syncGtfsData ( ) ;
22
+ } catch ( error ) {
23
+ console . error ( error ) ;
24
+ }
17
25
}
18
26
}
Original file line number Diff line number Diff line change
1
+ import { CacheInterceptor } from "@nestjs/cache-manager" ;
2
+ import {
3
+ Controller ,
4
+ Get ,
5
+ HttpException ,
6
+ HttpStatus ,
7
+ Param ,
8
+ UseInterceptors ,
9
+ Version ,
10
+ } from "@nestjs/common" ;
11
+ import { ApiParam , ApiTags } from "@nestjs/swagger" ;
12
+
13
+ import { EndpointVersion } from "src/enums/endpoint-version" ;
14
+ import { RouteService } from "src/modules/route/route.service" ;
15
+
16
+ @ApiTags ( "route" )
17
+ @Controller ( "route" )
18
+ @UseInterceptors ( CacheInterceptor )
19
+ export class RouteController {
20
+ constructor ( private readonly routeService : RouteService ) { }
21
+
22
+ @Get ( ":id" )
23
+ @Version ( [ EndpointVersion . v1 ] )
24
+ @ApiParam ( {
25
+ name : "id" ,
26
+ description : "Route ID" ,
27
+ required : true ,
28
+ example : "L991" ,
29
+ type : "string" ,
30
+ } )
31
+ async getRoute ( @Param ( "id" ) id : unknown ) {
32
+ if ( typeof id !== "string" ) {
33
+ throw new HttpException ( "Missing route ID" , HttpStatus . BAD_REQUEST ) ;
34
+ }
35
+
36
+ return this . routeService . getRoute ( id ) ;
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ import { Module } from "@nestjs/common" ;
2
+
3
+ import { RouteController } from "src/modules/route/route.controller" ;
4
+ import { RouteService } from "src/modules/route/route.service" ;
5
+
6
+ @Module ( {
7
+ controllers : [ RouteController ] ,
8
+ providers : [ RouteService ] ,
9
+ imports : [ ] ,
10
+ } )
11
+ export class RouteModule { }
Original file line number Diff line number Diff line change
1
+ import { Injectable } from "@nestjs/common" ;
2
+ import { group , unique } from "radash" ;
3
+
4
+ import { platformSelect } from "src/modules/platform/platform.service" ;
5
+ import { PrismaService } from "src/modules/prisma/prisma.service" ;
6
+
7
+ const gtfsRouteSelect = {
8
+ id : true ,
9
+ shortName : true ,
10
+ longName : true ,
11
+ isNight : true ,
12
+ color : true ,
13
+ url : true ,
14
+ type : true ,
15
+ } ;
16
+
17
+ const gtfsRouteStopSelect = {
18
+ directionId : true ,
19
+ stopId : true ,
20
+ stopSequence : true ,
21
+ } ;
22
+
23
+ @Injectable ( )
24
+ export class RouteService {
25
+ constructor ( private prisma : PrismaService ) { }
26
+
27
+ async getRoute ( id : string ) {
28
+ const route = await this . prisma . gtfsRoute . findFirst ( {
29
+ select : gtfsRouteSelect ,
30
+ where : {
31
+ id,
32
+ } ,
33
+ } ) ;
34
+
35
+ const routeStops = await this . prisma . gtfsRouteStop . findMany ( {
36
+ select : gtfsRouteStopSelect ,
37
+ where : {
38
+ routeId : id ,
39
+ } ,
40
+ orderBy : {
41
+ stopSequence : "asc" ,
42
+ } ,
43
+ } ) ;
44
+
45
+ const stops = await this . prisma . platform . findMany ( {
46
+ select : platformSelect ,
47
+ where : {
48
+ id : {
49
+ in : unique ( routeStops . map ( ( item ) => item . stopId ) ) ,
50
+ } ,
51
+ } ,
52
+ } ) ;
53
+
54
+ return {
55
+ ...route ,
56
+ directions : group (
57
+ routeStops . map ( ( routeStop ) => ( {
58
+ ...routeStop ,
59
+ stop : stops . find ( ( stop ) => stop . id === routeStop . stopId ) ,
60
+ } ) ) ,
61
+ ( item ) => item . directionId ,
62
+ ) ,
63
+ } ;
64
+ }
65
+ }
You can’t perform that action at this time.
0 commit comments