Skip to content

Commit f487cfa

Browse files
committed
added new response for empty mongo queries
1 parent fcfe3d3 commit f487cfa

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ notifications:
99
on_success: never
1010
on_failure: always
1111
after_success:
12-
- ./scripts/docker_build.sh
12+
- ./scripts/docker_build.sh
13+

routes/v1-launches.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ v1.get("/", (req, res) => {
2020
if (year) {
2121
global.db.collection("launch").find({"launch_year": `${year}`}, {"_id": 0 }).sort({"flight_number": -1})
2222
.toArray((err, doc) => {
23-
if (doc[0] === undefined) {
24-
res.end("No results found")
23+
if (doc.length == 0) {
24+
res.end("No Matches Found")
2525
}
2626
res.end(JSON.stringify(doc, null, 2))
2727
})
2828
} else if (start && final) {
2929
global.db.collection("launch").find({ "launch_date_utc": {"$gte": `${start}T00:00:00Z`, "$lte": `${final}T00:00:00Z`}}, {"_id": 0 })
3030
.sort({"flight_number": 1})
3131
.toArray((err, doc) => {
32-
if (doc[0] === undefined) {
33-
res.end("No results found")
32+
if (doc.length == 0) {
33+
res.end("No Matches Found")
3434
}
3535
res.end(JSON.stringify(doc, null, 2))
3636
})
@@ -49,8 +49,8 @@ v1.get("/cores/:core", (req, res) => {
4949
global.db.collection("launch").find({"core_serial": `${core}`},{"_id": 0}).sort({"core_serial": 1})
5050
.toArray((err, doc) => {
5151
if (err) return console.log(err)
52-
if (doc[0] === undefined) {
53-
res.end("No results found")
52+
if (doc.length == 0) {
53+
res.end("No Matches Found")
5454
}
5555
res.end(JSON.stringify(doc, null, 2))
5656
})
@@ -62,8 +62,8 @@ v1.get("/caps/:cap", (req, res) => {
6262
global.db.collection("launch").find({"cap_serial": `${cap}`},{"_id": 0}).sort({"capsule_serial": 1})
6363
.toArray((err, doc) => {
6464
if (err) return console.log(err)
65-
if (doc[0] === undefined) {
66-
res.end("No results found")
65+
if (doc.length == 0) {
66+
res.end("No Matches Found")
6767
}
6868
res.end(JSON.stringify(doc, null, 2))
6969
})

routes/v1-launchpad.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ v1.get("/", (req, res) => {
1414
v1.get("/:pad", (req, res) => {
1515
let id = req.params.pad
1616
global.db.collection("launchpad").find({"id": `${id}`}, {"_id": 0 }).toArray((err, doc) => {
17-
if (doc[0] === undefined) {
18-
res.end("No results found")
17+
if (doc.length == 0) {
18+
res.end("No Matches Found")
1919
}
2020
res.end(JSON.stringify(doc[0], null, 2))
2121
})

routes/v1-parts.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ v1.get("/caps/:cap", (req, res) => {
1818
global.db.collection("capsule").find({"capsule_serial": `${cap}`},{"_id": 0}).sort({"capsule_serial": 1})
1919
.toArray((err, doc) => {
2020
if (err) return console.log(err)
21-
if (doc[0] === undefined) {
22-
res.end("No results found")
21+
if (doc.length == 0) {
22+
res.end("No Matches Found")
2323
}
2424
res.end(JSON.stringify(doc[0], null, 2))
2525
})
@@ -40,8 +40,8 @@ v1.get("/cores/:core", (req, res) => {
4040
global.db.collection("core").find({"core_serial": `${core}`},{"_id": 0}).sort({"core_serial": 1})
4141
.toArray((err, doc) => {
4242
if (err) return console.log(err)
43-
if (doc[0] === undefined) {
44-
res.end("No results found")
43+
if (doc.length == 0) {
44+
res.end("No Matches Found")
4545
}
4646
res.end(JSON.stringify(doc[0], null, 2))
4747
})

routes/v1-upcoming.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ v1.get("/", (req, res) => {
1111
if (year) {
1212
global.db.collection("upcoming").find({"launch_year": `${year}`}, {"_id": 0 }).sort({"flight_number": -1})
1313
.toArray((err, doc) => {
14-
if (doc[0] === undefined) {
15-
res.end("No results found")
14+
if (doc.length == 0) {
15+
res.end("No Matches Found")
1616
}
1717
res.end(JSON.stringify(doc, null, 2))
1818
})
1919
} else if (start && final) {
2020
global.db.collection("upcoming").find({ "launch_date_utc": {"$gte": `${start}T00:00:00Z`, "$lte": `${final}T00:00:00Z`}}, {"_id": 0 })
2121
.sort({"flight_number": 1})
2222
.toArray((err, doc) => {
23-
if (doc[0] === undefined) {
24-
res.end("No results found")
23+
if (doc.length == 0) {
24+
res.end("No Matches Found")
2525
}
2626
res.end(JSON.stringify(doc, null, 2))
2727
})

0 commit comments

Comments
 (0)