summaryrefslogtreecommitdiffstats
path: root/server/api
diff options
context:
space:
mode:
authorUdo Walter2019-03-30 22:49:02 +0100
committerUdo Walter2019-03-30 22:49:02 +0100
commit8a4383885cb6bc19a2ce16bbad31ff0beada5ae2 (patch)
tree6d59120c2cea7c9d7e07d201af8f080d45a35945 /server/api
parent[webapp] fix bug in groups; remember filters in systemlog (diff)
downloadbas-8a4383885cb6bc19a2ce16bbad31ff0beada5ae2.tar.gz
bas-8a4383885cb6bc19a2ce16bbad31ff0beada5ae2.tar.xz
bas-8a4383885cb6bc19a2ce16bbad31ff0beada5ae2.zip
[server] configurator api -> ipxeconfigs and ipxeentries api; [webapp] ui polishing
Diffstat (limited to 'server/api')
-rw-r--r--server/api/ipxeconfigs.js (renamed from server/api/configurator.js)62
-rw-r--r--server/api/ipxeentries.js56
2 files changed, 80 insertions, 38 deletions
diff --git a/server/api/configurator.js b/server/api/ipxeconfigs.js
index 4ae1f35..a53e7ae 100644
--- a/server/api/configurator.js
+++ b/server/api/ipxeconfigs.js
@@ -1,5 +1,6 @@
/* global __appdir */
var path = require('path')
+var Sequelize = require('sequelize')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
var express = require('express')
const { decorateApp } = require('@awaitjs/express')
@@ -8,17 +9,27 @@ var router = decorateApp(express.Router())
// ############################################################################
// ########################### GET requests #################################
-router.getAsync('/configs', async (req, res) => {
- const configs = await db.config.findAll({ order: [['name', 'ASC']] })
+router.getAsync('', async (req, res) => {
+ const configs = await db.config.findAll({
+ include: [{ association: 'groups', attributes: [] }, { association: 'clients', attributes: [] }],
+ attributes: {
+ include: [
+ [Sequelize.fn('COUNT', Sequelize.col('groups.id')), 'groupCount'],
+ [Sequelize.fn('COUNT', Sequelize.col('clients.id')), 'clientCount']
+ ]
+ },
+ group: ['id']
+ })
res.status(200).send(configs)
})
-router.getAsync('/entries', async (req, res) => {
- const entries = await db.entry.findAll({ order: [['name', 'ASC']] })
- res.status(200).send(entries)
+router.getAsync('/:id', async (req, res) => {
+ const config = await db.config.findOne({ where: { id: req.params.id }, include: ['groups', 'clients'] })
+ if (config) res.status(200).send(config)
+ else res.status(404).end()
})
-router.getAsync('/configs/:id/entries', async (req, res) => {
+router.getAsync('/:id/entries', async (req, res) => {
const config = await db.config.findOne({
where: { id: req.params.id },
include: ['entries'],
@@ -28,13 +39,13 @@ router.getAsync('/configs/:id/entries', async (req, res) => {
else res.status(404).end()
})
-router.getAsync('/configs/:id/groups', async (req, res) => {
+router.getAsync('/:id/groups', async (req, res) => {
const config = await db.config.findOne({ where: { id: req.params.id }, include: ['groups'] })
if (config) res.status(200).send(config.groups)
else res.status(404).end()
})
-router.getAsync('/configs/:id/clients', async (req, res) => {
+router.getAsync('/:id/clients', async (req, res) => {
const config = await db.config.findOne({ where: { id: req.params.id }, include: ['clients'] })
if (config) res.status(200).send(config.clients)
else res.status(404).end()
@@ -43,7 +54,7 @@ router.getAsync('/configs/:id/clients', async (req, res) => {
// ############################################################################
// ########################## POST requests #################################
-router.postAsync(['/configs', '/configs/:id'], async (req, res) => {
+router.postAsync(['', '/:id'], async (req, res) => {
if (req.query.delete !== undefined && req.query.delete !== 'false') {
const count = await db.config.destroy({ where: { id: req.body.ids } })
res.status(200).send({ count })
@@ -70,29 +81,10 @@ router.postAsync(['/configs', '/configs/:id'], async (req, res) => {
}
})
-router.postAsync(['/entries', '/entries/:id'], async (req, res) => {
- if (req.query.delete !== undefined && req.query.delete !== 'false') {
- const count = await db.entry.destroy({ where: { id: req.body.ids } })
- res.status(200).send({ count })
- } else {
- let entry
- if (req.params.id === undefined) entry = await db.entry.create(req.body.data)
- else {
- entry = await db.entry.findOne({ where: { id: req.params.id } })
- if (entry) await entry.update(req.body.data)
- }
- if (entry) {
- res.status(200).send({ id: entry.id })
- } else {
- res.status(404).end()
- }
- }
-})
-
// ############################################################################
-// ########################## POST requests #################################
+// ########################### PUT requests #################################
-router.putAsync('/configs/:id/groups', async (req, res) => {
+router.putAsync('/:id/groups', async (req, res) => {
const config = await db.config.findOne({ where: { id: req.params.id } })
if (config) {
await config.setGroups(req.body.ids)
@@ -100,7 +92,7 @@ router.putAsync('/configs/:id/groups', async (req, res) => {
} else { res.status(404).end() }
})
-router.putAsync('/configs/:id/clients', async (req, res) => {
+router.putAsync('/:id/clients', async (req, res) => {
const config = await db.config.findOne({ where: { id: req.params.id } })
if (config) {
await config.setClients(req.body.ids)
@@ -111,18 +103,12 @@ router.putAsync('/configs/:id/clients', async (req, res) => {
// ############################################################################
// ########################## DELETE requests ###############################
-router.deleteAsync('/configs/:id', async (req, res) => {
+router.deleteAsync('/:id', async (req, res) => {
const count = await db.config.destroy({ where: { id: req.params.id } })
if (count) res.status(200).end()
else res.status(404).end()
})
-router.deleteAsync('/entries/:id', async (req, res) => {
- const count = await db.entry.destroy({ where: { id: req.params.id } })
- if (count) res.status(200).end()
- else res.status(404).end()
-})
-
// ############################################################################
// ############################################################################
diff --git a/server/api/ipxeentries.js b/server/api/ipxeentries.js
new file mode 100644
index 0000000..25cfd21
--- /dev/null
+++ b/server/api/ipxeentries.js
@@ -0,0 +1,56 @@
+/* global __appdir */
+var path = require('path')
+var db = require(path.join(__appdir, 'lib', 'sequelize'))
+var express = require('express')
+const { decorateApp } = require('@awaitjs/express')
+var router = decorateApp(express.Router())
+
+// ############################################################################
+// ########################### GET requests #################################
+
+router.getAsync('', async (req, res) => {
+ const entries = await db.entry.findAll()
+ res.status(200).send(entries)
+})
+
+router.getAsync('/:id', async (req, res) => {
+ const entry = await db.entry.findOne({ where: { id: req.params.id }})
+ if (entry) res.status(200).send(entry)
+ else res.status(404).end()
+})
+
+// ############################################################################
+// ########################## POST requests #################################
+
+router.postAsync(['', '/:id'], async (req, res) => {
+ if (req.query.delete !== undefined && req.query.delete !== 'false') {
+ const count = await db.entry.destroy({ where: { id: req.body.ids } })
+ res.status(200).send({ count })
+ } else {
+ let entry
+ if (req.params.id === undefined) entry = await db.entry.create(req.body.data)
+ else {
+ entry = await db.entry.findOne({ where: { id: req.params.id } })
+ if (entry) await entry.update(req.body.data)
+ }
+ if (entry) {
+ res.status(200).send({ id: entry.id })
+ } else {
+ res.status(404).end()
+ }
+ }
+})
+
+// ############################################################################
+// ########################## DELETE requests ###############################
+
+router.deleteAsync('/:id', async (req, res) => {
+ const count = await db.entry.destroy({ where: { id: req.params.id } })
+ if (count) res.status(200).end()
+ else res.status(404).end()
+})
+
+// ############################################################################
+// ############################################################################
+
+module.exports.router = router