@@ -56,25 +56,71 @@ v1.get("/", (req, res, next) => {
5656// Returns launches by core serial #
5757v1 . get ( "/cores/:core" , ( req , res , next ) => {
5858 const core = req . params . core
59- global . db . collection ( "launch" ) . find ( { "core_serial" : `${ core } ` } , { "_id" : 0 } ) . sort ( { "core_serial" : 1 } )
60- . toArray ( ( err , doc ) => {
61- if ( err ) {
62- return next ( err )
63- }
64- res . json ( doc )
65- } )
59+ const year = req . query . year
60+ const start = req . query . start
61+ const final = req . query . final
62+ const site = req . query . site
63+ if ( year && core ) {
64+ global . db . collection ( "launch" ) . find ( { "core_serial" : `${ core } ` , "launch_year" : `${ year } ` } , { "_id" : 0 } ) . sort ( { "flight_number" : - 1 } )
65+ . toArray ( ( err , doc ) => {
66+ res . json ( doc )
67+ } )
68+ } else if ( start && final && core ) {
69+ global . db . collection ( "launch" ) . find ( { "core_serial" : `${ core } ` , "launch_date_utc" : { "$gte" : `${ start } T00:00:00Z` , "$lte" : `${ final } T00:00:00Z` } } , { "_id" : 0 } )
70+ . sort ( { "flight_number" : 1 } )
71+ . toArray ( ( err , doc ) => {
72+ res . json ( doc )
73+ } )
74+ } else if ( site && core ) {
75+ global . db . collection ( "launch" ) . find ( { "core_serial" : `${ core } ` , "launch_site.site_id" : `${ site } ` } , { "_id" : 0 } )
76+ . sort ( { "flight_number" : 1 } )
77+ . toArray ( ( err , doc ) => {
78+ res . json ( doc )
79+ } )
80+ } else if ( core ) {
81+ global . db . collection ( "launch" ) . find ( { "core_serial" : `${ core } ` } , { "_id" : 0 } ) . sort ( { "core_serial" : 1 } )
82+ . toArray ( ( err , doc ) => {
83+ if ( err ) {
84+ return next ( err )
85+ }
86+ res . json ( doc )
87+ } )
88+ }
6689} )
6790
6891// Returns launches by capsule serial #
6992v1 . get ( "/caps/:cap" , ( req , res , next ) => {
7093 const cap = req . params . cap
71- global . db . collection ( "launch" ) . find ( { "cap_serial" : `${ cap } ` } , { "_id" : 0 } ) . sort ( { "capsule_serial" : 1 } )
72- . toArray ( ( err , doc ) => {
73- if ( err ) {
74- return next ( err )
75- }
76- res . json ( doc )
77- } )
94+ const year = req . query . year
95+ const start = req . query . start
96+ const final = req . query . final
97+ const site = req . query . site
98+ if ( year && cap ) {
99+ global . db . collection ( "launch" ) . find ( { "cap_serial" : `${ cap } ` , "launch_year" : `${ year } ` } , { "_id" : 0 } ) . sort ( { "flight_number" : - 1 } )
100+ . toArray ( ( err , doc ) => {
101+ res . json ( doc )
102+ } )
103+ } else if ( start && final && cap ) {
104+ global . db . collection ( "launch" ) . find ( { "cap_serial" : `${ cap } ` , "launch_date_utc" : { "$gte" : `${ start } T00:00:00Z` , "$lte" : `${ final } T00:00:00Z` } } , { "_id" : 0 } )
105+ . sort ( { "flight_number" : 1 } )
106+ . toArray ( ( err , doc ) => {
107+ res . json ( doc )
108+ } )
109+ } else if ( site && cap ) {
110+ global . db . collection ( "launch" ) . find ( { "cap_serial" : `${ cap } ` , "launch_site.site_id" : `${ site } ` } , { "_id" : 0 } )
111+ . sort ( { "flight_number" : 1 } )
112+ . toArray ( ( err , doc ) => {
113+ res . json ( doc )
114+ } )
115+ } else {
116+ global . db . collection ( "launch" ) . find ( { "cap_serial" : `${ cap } ` } , { "_id" : 0 } ) . sort ( { "capsule_serial" : 1 } )
117+ . toArray ( ( err , doc ) => {
118+ if ( err ) {
119+ return next ( err )
120+ }
121+ res . json ( doc )
122+ } )
123+ }
78124} )
79125
80126// Returns all ASDS launches
0 commit comments