22
33const express = require ( "express" )
44const v1 = express . Router ( )
5- const error = { error : "No results found" }
65
76// Get most recent launch
8- v1 . get ( "/latest" , ( req , res ) => {
7+ v1 . get ( "/latest" , ( req , res , next ) => {
98 global . db . collection ( "launch" ) . find ( { } , { "_id" : 0 } ) . sort ( { "flight_number" : - 1 } ) . limit ( 1 )
109 . toArray ( ( err , doc ) => {
11- if ( err ) return console . log ( err )
10+ if ( err ) {
11+ return next ( err )
12+ }
1213 res . json ( doc )
1314 } )
1415} )
1516
1617// All launches by date, year, or default to all launches
17- v1 . get ( "/" , ( req , res ) => {
18+ v1 . get ( "/" , ( req , res , next ) => {
1819 const year = req . query . year
1920 const start = req . query . start
2021 const final = req . query . final
@@ -28,7 +29,6 @@ v1.get("/", (req, res) => {
2829 global . db . collection ( "launch" ) . find ( { "launch_date_utc" : { "$gte" : `${ start } T00:00:00Z` , "$lte" : `${ final } T00:00:00Z` } } , { "_id" : 0 } )
2930 . sort ( { "flight_number" : 1 } )
3031 . toArray ( ( err , doc ) => {
31- if ( doc . length == 0 ) {
3232 res . json ( doc )
3333 } )
3434 } else if ( site ) {
@@ -40,46 +40,56 @@ v1.get("/", (req, res) => {
4040 } else {
4141 global . db . collection ( "launch" ) . find ( { } , { "_id" : 0 } ) . sort ( { "flight_number" : 1 } )
4242 . toArray ( ( err , doc ) => {
43- if ( err ) return console . log ( err )
43+ if ( err ) {
44+ return next ( err )
45+ }
4446 res . json ( doc )
4547 } )
4648 }
4749} )
4850
4951// Returns launches by core serial #
50- v1 . get ( "/cores/:core" , ( req , res ) => {
52+ v1 . get ( "/cores/:core" , ( req , res , next ) => {
5153 const core = req . params . core
5254 global . db . collection ( "launch" ) . find ( { "core_serial" : `${ core } ` } , { "_id" : 0 } ) . sort ( { "core_serial" : 1 } )
5355 . toArray ( ( err , doc ) => {
54- if ( err ) return console . log ( err )
56+ if ( err ) {
57+ return next ( err )
58+ }
5559 res . json ( doc )
5660 } )
5761} )
5862
5963// Returns launches by capsule serial #
60- v1 . get ( "/caps/:cap" , ( req , res ) => {
64+ v1 . get ( "/caps/:cap" , ( req , res , next ) => {
6165 const cap = req . params . cap
6266 global . db . collection ( "launch" ) . find ( { "cap_serial" : `${ cap } ` } , { "_id" : 0 } ) . sort ( { "capsule_serial" : 1 } )
6367 . toArray ( ( err , doc ) => {
64- if ( err ) return console . log ( err )
68+ if ( err ) {
69+ return next ( err )
70+ }
6571 res . json ( doc )
6672 } )
6773} )
6874
6975// Returns all ASDS launches
70- v1 . get ( "/asds" , ( req , res ) => {
76+ v1 . get ( "/asds" , ( req , res , next ) => {
7177 global . db . collection ( "launch" ) . find ( { "landing_type" : "ASDS" } , { "_id" : 0 } ) . sort ( { "flight_number" : 1 } )
7278 . toArray ( ( err , doc ) => {
73- if ( err ) return console . log ( err )
79+ if ( err ) {
80+ return next ( err )
81+ }
7482 res . json ( doc )
7583 } )
7684} )
7785
7886// Returns all RTLS launches
79- v1 . get ( "/rtls" , ( req , res ) => {
87+ v1 . get ( "/rtls" , ( req , res , next ) => {
8088 global . db . collection ( "launch" ) . find ( { "landing_type" : "RTLS" } , { "_id" : 0 } ) . sort ( { "flight_number" : 1 } )
8189 . toArray ( ( err , doc ) => {
82- if ( err ) return console . log ( err )
90+ if ( err ) {
91+ return next ( err )
92+ }
8393 res . json ( doc )
8494 } )
8595} )
0 commit comments