summaryrefslogtreecommitdiffstats
path: root/server/api
diff options
context:
space:
mode:
authorChristian Hofmaier2019-04-14 18:20:31 +0200
committerChristian Hofmaier2019-04-14 18:20:31 +0200
commit3f2d126dba95ace251cf49f952ffa0ada6729f65 (patch)
tree1423e40cc661735973951a3545f24e3f04f2cbfb /server/api
parent[webapp] remove unused npm dependencies (diff)
downloadbas-3f2d126dba95ace251cf49f952ffa0ada6729f65.tar.gz
bas-3f2d126dba95ace251cf49f952ffa0ada6729f65.tar.xz
bas-3f2d126dba95ace251cf49f952ffa0ada6729f65.zip
[eventmanager] show config name instead of config id in event table
- change models/migrations for config association
Diffstat (limited to 'server/api')
-rw-r--r--server/api/events.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/server/api/events.js b/server/api/events.js
index 23aeae7..5affbb0 100644
--- a/server/api/events.js
+++ b/server/api/events.js
@@ -13,7 +13,7 @@ var router = decorateApp(express.Router())
* @return: Returns event of given id.
*/
router.getAsync('/:id', async (req, res) => {
- var event = await db.event.findOne({ where: { id: req.params.id }, include: ['clients', 'groups'] })
+ var event = await db.event.findOne({ where: { id: req.params.id }, include: ['config', 'clients', 'groups'] })
if (event) res.send(event)
else res.status(404).end()
})
@@ -22,7 +22,7 @@ router.getAsync('/:id', async (req, res) => {
* @return: Returns a list of all events in the database.
*/
router.getAsync('', async (req, res) => {
- var events = await db.event.findAll({ include: ['clients', 'groups'] })
+ var events = await db.event.findAll({ include: ['config', 'clients', 'groups'] })
if (events) res.status(200).send(events)
else res.status(404).end()
})
@@ -30,6 +30,9 @@ router.getAsync('', async (req, res) => {
// ############################################################################
// ########################## POST requests #################################
+/*
+ * @return: Returns a list of all childs of the given groups
+ */
router.postAsync('/blacklist', async (req, res) => {
if (req.body.groups) {
var blacklist = await groupUtil.getAllChildren(req.body.groups)
@@ -51,7 +54,7 @@ router.postAsync(['', '/:id'], async (req, res) => {
// Update existing role
eventDb = await db.event.findOne({ where: { id: req.params.id } })
if (eventDb !== null) {
- promises.push(eventDb.update({ name: req.body.name, description: req.body.description, config: req.body.config || null, times: req.body.times, important: req.body.important }))
+ promises.push(eventDb.update({ name: req.body.name, description: req.body.description, times: req.body.times, important: req.body.important, configId: req.body.config || null }))
promises.push(eventDb.setGroups(req.body.groups, { through: { blacklist: 0 } }))
promises.push(eventDb.setClients(req.body.clients, { through: { blacklist: 0 } }))
await Promise.all(promises)
@@ -64,7 +67,7 @@ router.postAsync(['', '/:id'], async (req, res) => {
}
} else {
// Create new role
- eventDb = await db.event.create({ name: req.body.name, description: req.body.description, config: req.body.config || null, times: req.body.times, important: req.body.important })
+ eventDb = await db.event.create({ name: req.body.name, description: req.body.description, times: req.body.times, important: req.body.important, configId: req.body.config || null })
promises.push(eventDb.setGroups(req.body.groups, { through: { blacklist: 0 } }))
promises.push(eventDb.setClients(req.body.clients, { through: { blacklist: 0 } }))
await Promise.all(promises)