From 37b120d2bdf7d306df3b3b3c77983b9cd308f591 Mon Sep 17 00:00:00 2001 From: Haris Razis Date: Mon, 11 Jan 2021 13:18:46 +0200 Subject: [PATCH] Allow athlete adopting by providing ID --- client/services/socket.js | 5 + server/routes/athletes.js | 10 +- web/src/store/modules/athletes.ts | 2 +- web/src/views/Athlete.vue | 68 ++++++++++-- web/src/views/Athletes.vue | 174 ++++++++++++++++++++++-------- 5 files changed, 204 insertions(+), 55 deletions(-) diff --git a/client/services/socket.js b/client/services/socket.js index 307f3c6..773cfa0 100644 --- a/client/services/socket.js +++ b/client/services/socket.js @@ -6,6 +6,11 @@ const getMAC = require('getmac').default const socket = io(server_url); const mac = getMAC(); +console.log(chalk.green(` + ID: ${mac} + Use this ID, to adopt the athlete on the user dashboard. +`)) + socket.on('connect', () => { console.log(chalk.green('Connected to server!')); diff --git a/server/routes/athletes.js b/server/routes/athletes.js index 6a1bb35..a390e31 100644 --- a/server/routes/athletes.js +++ b/server/routes/athletes.js @@ -39,7 +39,15 @@ router.put('/api/athletes/:id', const {name, _trainer} = req.body const updateAthlete = {name, _trainer} - if (name || _trainer) + if (_trainer === '') { + updateAthlete._trainer = undefined + await Athlete.findByIdAndUpdate(req.params.id, updateAthlete, {}, (err, athlete) => { + if (err) + return res.status(400).json({errors: 'Something went wrong!'}); + + return res.send(athlete) + }) + } else if (name || _trainer) await Athlete.findByIdAndUpdate(req.params.id, updateAthlete, {}, (err, athlete) => { if (err) return res.status(400).json({errors: 'Something went wrong!'}); diff --git a/web/src/store/modules/athletes.ts b/web/src/store/modules/athletes.ts index a65e47b..26569dc 100644 --- a/web/src/store/modules/athletes.ts +++ b/web/src/store/modules/athletes.ts @@ -8,7 +8,7 @@ export interface AthleteInterface { id: string, socketID: string, name: string, - _trainer: UserInterface + _trainer: string } @Module diff --git a/web/src/views/Athlete.vue b/web/src/views/Athlete.vue index 5398c2e..9860a39 100644 --- a/web/src/views/Athlete.vue +++ b/web/src/views/Athlete.vue @@ -1,5 +1,30 @@