From 2ee4616da56ad881a66d3b0f34cb272f61cba3fb Mon Sep 17 00:00:00 2001 From: Joshua Collins Date: Thu, 20 Aug 2020 09:48:28 -0400 Subject: [PATCH] fixing errors with agent tasks --- app/app.js | 15 +++++---------- app/store/tasks.js | 4 +--- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/app.js b/app/app.js index 50693fe..66541b7 100644 --- a/app/app.js +++ b/app/app.js @@ -47,21 +47,16 @@ app.get('/api/agents/:agentId', (req, res) => { } }) -app.put('/api/agents/:agentId/status', (req, res) => { - const agentId = parseInt(req.params.agentId) - agentStore.updateAgentBeaconTime(agentId) - res.status(200).send() -}) - app.get('/api/agents/:agentId/tasks', (req, res) => { const agentId = parseInt(req.params.agentId) - const tasks = taskStore.getAllTasksForAgent(agentId) - if (tasks) { - res.status(200).json(tasks) - } else { + const agent = agentStore.getAgentById(agentId) + if (!agent) { res.status(404).json({ message: 'agent does not exist' }) + } else { + const tasks = taskStore.getAllTasksForAgent(agentId) + res.status(200).json(tasks) } }) diff --git a/app/store/tasks.js b/app/store/tasks.js index f4e4d65..f87b34d 100644 --- a/app/store/tasks.js +++ b/app/store/tasks.js @@ -39,9 +39,7 @@ const Tasks = () => { obj.getAllTasksForAgent = (agentId) => { const tasks = obj.tasks.filter(t => t.agentId === agentId) - return tasks.length !== 0 - ? tasks - : null + return tasks } obj.getAllTasks = () => obj.tasks