From 33e8cbdb83e19bbaf567b4b711711b4e860df779 Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Sun, 22 Nov 2020 10:44:21 +0100 Subject: [PATCH] refactor: reorder /begin /add /end routes --- routes/api/tracks.js | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/routes/api/tracks.js b/routes/api/tracks.js index 32a24d8..8fa2ef4 100644 --- a/routes/api/tracks.js +++ b/routes/api/tracks.js @@ -169,6 +169,28 @@ router.post( }), ); +router.post( + '/begin', + auth.optional, + wrapRoute(async (req, res) => { + const user = await User.findById(req.body.id); + + if (!user) { + return res.sendStatus(401); + } + + const track = new Track(req.body.track); + const trackData = new TrackData(); + track.trackData = trackData._id; + track.author = user; + + // remember which is the actively building track for this user + currentTracks.set(user.id, track._id); + + return res.sendStatus(200); + }), +); + router.post( '/add', auth.optional, @@ -197,28 +219,6 @@ router.post( }), ); -router.post( - '/begin', - auth.optional, - wrapRoute(async (req, res) => { - const user = await User.findById(req.body.id); - - if (!user) { - return res.sendStatus(401); - } - - const track = new Track(req.body.track); - const trackData = new TrackData(); - track.trackData = trackData._id; - track.author = user; - - // remember which is the actively building track for this user - currentTracks.set(user.id, track._id); - - return res.sendStatus(200); - }), -); - router.post( '/end', auth.optional,