From 3f2d126dba95ace251cf49f952ffa0ada6729f65 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Sun, 14 Apr 2019 16:20:31 +0000 Subject: [eventmanager] show config name instead of config id in event table - change models/migrations for config association --- server/api/events.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'server/api') 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) -- cgit v1.2.3-55-g7522