summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorUdo Walter2018-08-01 22:17:33 +0200
committerUdo Walter2018-08-01 22:17:33 +0200
commitfaf1188d03e1302dd615a118bce73dd6197be8f1 (patch)
tree207d484a6d68f3d77bc49815ea92c13f4da057c3 /server
parent[server/idoit] iDoIT api call returns now the object itself and the childs. (diff)
downloadbas-faf1188d03e1302dd615a118bce73dd6197be8f1.tar.gz
bas-faf1188d03e1302dd615a118bce73dd6197be8f1.tar.xz
bas-faf1188d03e1302dd615a118bce73dd6197be8f1.zip
[groups] add edit functionality to group infos
Diffstat (limited to 'server')
-rw-r--r--server/api/clients.js16
-rw-r--r--server/api/groups.js42
-rw-r--r--server/migrations/20180717132233-create-group.js2
-rw-r--r--server/migrations/20180717132333-create-client.js2
-rw-r--r--server/migrations/20180717202333-create-group_x_group.js4
-rw-r--r--server/migrations/20180717202533-create-group_x_client.js4
-rw-r--r--server/models/client.js4
-rw-r--r--server/models/group.js7
8 files changed, 45 insertions, 36 deletions
diff --git a/server/api/clients.js b/server/api/clients.js
index d494fd0..8daab55 100644
--- a/server/api/clients.js
+++ b/server/api/clients.js
@@ -10,11 +10,17 @@ module.exports.get = {
})
},
- getGroups: function (req, res) {
- db.client.findOne({ where: { id: req.query.id } }).then(client => {
- client.getGroups().then(groups => {
- res.send(groups)
- })
+ // get all clients that have no groups
+ getTopLevel: function (req, res) {
+ db.client.findAll({ where: { '$groups.id$': null }, include: ['groups'] }).then(clients => {
+ res.send(clients)
+ })
+ },
+
+ // get name, description, ip, mac and uuid of a client (by id)
+ getClient: function (req, res) {
+ db.client.findOne({ where: { id: req.query.id }, include: ['groups'] }).then(client => {
+ res.send(client)
})
}
}
diff --git a/server/api/groups.js b/server/api/groups.js
index fa2c1ca..5916585 100644
--- a/server/api/groups.js
+++ b/server/api/groups.js
@@ -4,42 +4,42 @@ var db = require(path.join(__appdir, 'lib', 'sequelize'))
// GET Requests
module.exports.get = {
+ // get a list containing id and name of all groups
getList: function (req, res) {
db.group.findAll({ attributes: ['id', 'name'] }).then(list => {
res.send(list)
})
},
- getParents: function (req, res) {
- const id = req.query.id > 0 ? req.query.id : null
- db.group.findOne({ where: { id: id }, include: ['parents'] }).then(group => {
- group.getParents().then(parents => {
- res.send(parents)
- })
+ // get all groups that have no parents
+ getTopLevel: function (req, res) {
+ db.group.findAll({ where: { '$parents.id$': null }, include: ['parents'] }).then(groups => {
+ res.send(groups)
})
},
- getSubGroups: function (req, res) {
- const id = req.query.id > 0 ? req.query.id : null
- db.group.findAll({ where: { '$parents.id$': id }, include: ['parents'] }).then(subgroups => {
- res.send(subgroups)
- })
- },
-
- getClients: function (req, res) {
- const id = req.query.id > 0 ? req.query.id : null
- db.client.findAll({ where: { '$groups.id$': id }, include: ['groups'] }).then(clients => {
- res.send(clients)
+ // get name, description, parents, subgroups and clients of a group (by id)
+ getGroup: function (req, res) {
+ db.group.findOne({ where: { id: req.query.id }, include: ['parents', 'subgroups', 'clients'] }).then(group => {
+ res.send(group)
})
}
}
// POST Requests
module.exports.post = {
- update: function (req, res) {
+ // create group or update information of a group (returns id)
+ saveInfo: function (req, res) {
const id = req.body.id > 0 ? req.body.id : null
- if (!id) res.end()
- db.group.update({ name: req.body.name }, { where: { id: id } })
- res.end()
+ if (id) {
+ db.group.findOne({ where: { id: id } }).then(group => {
+ Promise.all([
+ group.update({ name: req.body.name, description: req.body.description }),
+ group.setParents(req.body.parentIds)
+ ]).then(() => { res.send({id}) })
+ })
+ } else {
+ res.end()
+ }
}
}
diff --git a/server/migrations/20180717132233-create-group.js b/server/migrations/20180717132233-create-group.js
index 71258dd..49088dd 100644
--- a/server/migrations/20180717132233-create-group.js
+++ b/server/migrations/20180717132233-create-group.js
@@ -12,7 +12,7 @@ module.exports = {
type: Sequelize.STRING
},
description: {
- type: Sequelize.STRING
+ type: Sequelize.STRING(2048)
}
})
},
diff --git a/server/migrations/20180717132333-create-client.js b/server/migrations/20180717132333-create-client.js
index 955f2f9..d374b22 100644
--- a/server/migrations/20180717132333-create-client.js
+++ b/server/migrations/20180717132333-create-client.js
@@ -12,7 +12,7 @@ module.exports = {
type: Sequelize.STRING
},
description: {
- type: Sequelize.STRING
+ type: Sequelize.STRING(2048)
},
ip: {
type: Sequelize.STRING
diff --git a/server/migrations/20180717202333-create-group_x_group.js b/server/migrations/20180717202333-create-group_x_group.js
index a40278d..298c2fb 100644
--- a/server/migrations/20180717202333-create-group_x_group.js
+++ b/server/migrations/20180717202333-create-group_x_group.js
@@ -6,7 +6,7 @@ module.exports = {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
- onDelete: "cascade",
+ onDelete: 'cascade',
references: {
model: 'groups',
key: 'id'
@@ -16,7 +16,7 @@ module.exports = {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
- onDelete: "cascade",
+ onDelete: 'cascade',
references: {
model: 'groups',
key: 'id'
diff --git a/server/migrations/20180717202533-create-group_x_client.js b/server/migrations/20180717202533-create-group_x_client.js
index 2330cdb..7564618 100644
--- a/server/migrations/20180717202533-create-group_x_client.js
+++ b/server/migrations/20180717202533-create-group_x_client.js
@@ -6,7 +6,7 @@ module.exports = {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
- onDelete: "cascade",
+ onDelete: 'cascade',
references: {
model: 'groups',
key: 'id'
@@ -16,7 +16,7 @@ module.exports = {
primaryKey: true,
allowNull: false,
type: Sequelize.INTEGER,
- onDelete: "cascade",
+ onDelete: 'cascade',
references: {
model: 'clients',
key: 'id'
diff --git a/server/models/client.js b/server/models/client.js
index 483d1e6..5789788 100644
--- a/server/models/client.js
+++ b/server/models/client.js
@@ -8,7 +8,7 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.INTEGER
},
name: DataTypes.STRING,
- description: DataTypes.STRING,
+ description: DataTypes.STRING(2048),
ip: DataTypes.STRING,
mac: DataTypes.STRING,
uuid: DataTypes.STRING
@@ -17,7 +17,7 @@ module.exports = (sequelize, DataTypes) => {
})
client.associate = function (models) {
var GroupXClient = sequelize.define('group_x_client', {}, { timestamps: false, freezeTableName: true })
- client.belongsToMany(models.group, { as: 'groups', through: GroupXClient, foreignKey: 'clientId', otherKey: 'groupId'})
+ client.belongsToMany(models.group, { as: 'groups', through: GroupXClient, foreignKey: 'clientId', otherKey: 'groupId' })
}
return client
}
diff --git a/server/models/group.js b/server/models/group.js
index e988497..62a5665 100644
--- a/server/models/group.js
+++ b/server/models/group.js
@@ -8,13 +8,16 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.INTEGER
},
name: DataTypes.STRING,
- description: DataTypes.STRING
+ description: DataTypes.STRING(2048)
}, {
timestamps: false
})
group.associate = function (models) {
var GroupXGroup = sequelize.define('group_x_group', {}, { timestamps: false, freezeTableName: true })
- group.belongsToMany(group, { as: 'parents', through: GroupXGroup, foreignKey: 'childId', otherKey: 'parentId'})
+ var GroupXClient = sequelize.define('group_x_client', {}, { timestamps: false, freezeTableName: true })
+ group.belongsToMany(group, { as: 'parents', through: GroupXGroup, foreignKey: 'childId', otherKey: 'parentId' })
+ group.belongsToMany(group, { as: 'subgroups', through: GroupXGroup, foreignKey: 'parentId', otherKey: 'childId' })
+ group.belongsToMany(models.client, { as: 'clients', through: GroupXClient, foreignKey: 'groupId', otherKey: 'clientId' })
}
return group
}