Skip to content

Commit ce041f1

Browse files
committed
added query param for launches by launch site
1 parent 29b480e commit ce041f1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

routes/v1-launches.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ v1.get("/", (req, res) => {
1717
let year = req.query.year
1818
let start = req.query.start
1919
let final = req.query.final
20+
const site = req.query.site
2021
if (year) {
2122
global.db.collection("launch").find({"launch_year": `${year}`}, {"_id": 0 }).sort({"flight_number": -1})
2223
.toArray((err, doc) => {
@@ -34,6 +35,15 @@ v1.get("/", (req, res) => {
3435
}
3536
res.end(JSON.stringify(doc, null, 2))
3637
})
38+
} else if (site) {
39+
global.db.collection("launch").find({ "launch_site.site_id": `${site}`}, {"_id": 0 })
40+
.sort({"flight_number": 1})
41+
.toArray((err, doc) => {
42+
if (doc.length == 0) {
43+
res.end("No Matches Found")
44+
}
45+
res.end(JSON.stringify(doc, null, 2))
46+
})
3747
} else {
3848
global.db.collection("launch").find({},{"_id": 0 }).sort({"flight_number": 1})
3949
.toArray((err, doc) => {

test/v1-all.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ test("It should return the latest launch", () => {
125125
})
126126
})
127127

128+
test("It should return all past launches from LC-4E", () => {
129+
return request(app).get("/v1/launches?site=vafb_slc_4e").then(response => {
130+
expect(response.statusCode).toBe(200)
131+
expect(response.text).toContain("vafb_slc_4e")
132+
})
133+
})
134+
135+
test("It should return no launches from made up launchpad", () => {
136+
return request(app).get("/v1/launches?site=vafb_slc_5e").then(response => {
137+
expect(response.statusCode).toBe(200)
138+
expect(response.text).toContain("No Matches Found")
139+
})
140+
})
141+
128142
test("It should return all 2012 launches", () => {
129143
return request(app).get("/v1/launches?year=2012").then(response => {
130144
expect(response.statusCode).toBe(200)

0 commit comments

Comments
 (0)