summaryrefslogtreecommitdiffstats
path: root/server/api/clients.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/clients.js')
-rw-r--r--server/api/clients.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/server/api/clients.js b/server/api/clients.js
index 32b845d..3152e10 100644
--- a/server/api/clients.js
+++ b/server/api/clients.js
@@ -35,14 +35,31 @@ router.postAsync(['', '/:id'], async (req, res) => {
} else {
let client
let action = 'updated'
+
+ let backendClient = {
+ id: req.params.id,
+ name: req.body.data.name,
+ type: 'CLIENT',
+ uuid: req.body.data.uuid,
+ parents: req.body.groupIds,
+ networks: [
+ { ip: req.body.data.ip, mac: req.body.data.mac }
+ ]
+ }
+
if (req.params.id === undefined) {
client = await db.client.create(req.body.data)
action = 'created'
io.in('broadcast newClient').emit('notifications newAlert', { type: 'info', text: 'New client!' })
+
+ // Add client to the backends
+ backendClient.id = client.id
+ backendHelper.addClient(backendClient)
} else if (req.params.id > 0) {
client = await db.client.findOne({ where: { id: req.params.id } })
if (!client) return HttpResponse.notFound(req.params.id).send(res)
else await client.update(req.body.data)
+ backendHelper.updateClient(backendClient)
} else {
return HttpResponse.invalidId().send(res)
}