From ab352ee80091467a6c50beb4fa1267badac2766b Mon Sep 17 00:00:00 2001 From: Haris Razis Date: Fri, 8 Jan 2021 18:53:13 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Add=20Athletes.vue=20and=20Athlete.?= =?UTF-8?q?vue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With all the corresponding store and router actions --- server/routes/athletes.js | 13 +++- web/src/components/Navbar.vue | 2 +- web/src/components/Sidebar.vue | 2 +- web/src/router/index.ts | 16 +++- web/src/store/index.ts | 4 +- web/src/store/modules/athletes.ts | 90 +++++++++++++++++++++ web/src/store/modules/user.ts | 34 +++++--- web/src/views/Athlete.vue | 125 ++++++++++++++++++++++++++++++ web/src/views/Athletes.vue | 75 ++++++++++++++++++ 9 files changed, 345 insertions(+), 16 deletions(-) create mode 100644 web/src/views/Athlete.vue create mode 100644 web/src/views/Athletes.vue diff --git a/server/routes/athletes.js b/server/routes/athletes.js index 18d52b5..96e01a7 100644 --- a/server/routes/athletes.js +++ b/server/routes/athletes.js @@ -21,8 +21,17 @@ router.get('/api/athletes/:id/edit', requireAuth, async (req, res) => { }); router.put('/api/athletes/:id', requireAuth, async (req, res) => { - const {id, user} = req.params - await Athlete.findByIdAndUpdate(id, user) + const {name, _trainer} = req.body + const updateAthlete = {name, _trainer} + + if (name || _trainer) + await Athlete.findByIdAndUpdate(req.params.id, updateAthlete, {}, (err, athlete) => { + if (err) + return res.status(400).json({errors: 'Something went wrong!0'}); + + res.send(athlete) + }) + }); router.delete('/api/athlete/:id', requireAuth, async (req, res) => { diff --git a/web/src/components/Navbar.vue b/web/src/components/Navbar.vue index 2c9ced3..3083343 100644 --- a/web/src/components/Navbar.vue +++ b/web/src/components/Navbar.vue @@ -22,7 +22,7 @@