Merge pull request #1 from exord66/master

Merge
sig-changes
sigonasr2, Sig, Sigo 5 years ago committed by GitHub
commit d137986f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      app/app.js
  2. 6
      app/store/tasks.js

@ -47,32 +47,34 @@ 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)
}
})
// 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) => {

@ -38,10 +38,8 @@ const Tasks = () => {
}
obj.getAllTasksForAgent = (agentId) => {
const tasks = objs.tasks.filter(t => t.agentId === agentId)
return tasks.length !== 0
? tasks
: null
const tasks = obj.tasks.filter(t => t.agentId === agentId)
return tasks
}
obj.getAllTasks = () => obj.tasks

Loading…
Cancel
Save