Skip to content

Commit

Permalink
Add condition for all launches to check order of launches before concat
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewmeyer committed Jun 30, 2018
1 parent 41c7dc9 commit d728fdf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/controllers/launches.js
Expand Up @@ -38,6 +38,7 @@ module.exports = {
* Return all past and upcoming launches
*/
all: async (ctx) => {
let data;
const past = await global.db
.collection('launch_v2')
.find(launchQuery(ctx.request))
Expand All @@ -52,7 +53,11 @@ module.exports = {
.sort(sortQuery(ctx.request))
.limit(limitQuery(ctx.request))
.toArray();
const data = past.concat(upcoming);
if (past[past.length - 1].flight_number === 1) {
data = upcoming.concat(past);
} else {
data = past.concat(upcoming);
}
ctx.body = data;
},

Expand Down

0 comments on commit d728fdf

Please sign in to comment.