added delete agent function

sig-changes^2
Joshua Collins 5 years ago
parent 1b7753ec46
commit 144518da57
  1. 12
      app/app.js
  2. 10
      app/store/agents.js

@ -60,6 +60,18 @@ app.get('/api/agents/:agentId/tasks', (req, res) => {
}
})
app.delete('/api/agents/:agentId', (req, res) => {
const agentId = parseInt(req.params.agentId)
const status = agentStore.deleteAgentById(agentId)
if (status) {
res.status(200).json(agentId)
} else {
res.status(404).json({
message: 'agent does not exist'
})
}
})
// Interact with tasks
app.post('/api/tasks', (req, res) => {
const { command, agentId } = req.body

@ -41,6 +41,16 @@ const Agents = () => {
return false
}
obj.deleteAgentById = (agentId) => {
const index = obj.findIndex(agent => agent.id === agentId)
if (index !== -1) {
obj.splice(index, 1)
return true
} else {
return false
}
}
obj.getAllAgents = () => obj.agents
return obj

Loading…
Cancel
Save