From 1b7753ec4657148597b85a2677857a6859487ad1 Mon Sep 17 00:00:00 2001 From: Joshua Collins Date: Thu, 20 Aug 2020 09:51:15 -0400 Subject: [PATCH] updated add task to check if agent exists first --- app/app.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/app.js b/app/app.js index 66541b7..35674ea 100644 --- a/app/app.js +++ b/app/app.js @@ -63,11 +63,18 @@ app.get('/api/agents/:agentId/tasks', (req, res) => { // Interact with tasks app.post('/api/tasks', (req, res) => { const { command, agentId } = req.body - const taskId = taskStore.addTask(command, agentId) - res.status(200).json({ - taskId: taskId, - agentId: agentId - }) + const agent = agentStore.getAgentById(agentId) + if (!agent) { + res.status(404).json({ + message: 'agent does not exist' + }) + } else { + const taskId = taskStore.addTask(command, agentId) + res.status(200).json({ + taskId: taskId, + agentId: agentId + }) + } }) app.get('/api/tasks', (req, res) => {