summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorUdo Walter2019-04-15 05:36:13 +0200
committerUdo Walter2019-04-15 05:36:13 +0200
commit9050fe25049560964f03cf1264dcab1a83f6b92f (patch)
tree83f27ac68c915c70d4b36bad01d812764d77f0a1 /server
parent[webapp/datatable] add sort by number and ipv4 (diff)
downloadbas-9050fe25049560964f03cf1264dcab1a83f6b92f.tar.gz
bas-9050fe25049560964f03cf1264dcab1a83f6b92f.tar.xz
bas-9050fe25049560964f03cf1264dcab1a83f6b92f.zip
[configurator] add ability to mark a config as default
Diffstat (limited to 'server')
-rw-r--r--server/api/ipxeconfigs.js12
-rw-r--r--server/migrations/20190415232633-add-isdefault-config.js13
-rw-r--r--server/models/config.js7
3 files changed, 31 insertions, 1 deletions
diff --git a/server/api/ipxeconfigs.js b/server/api/ipxeconfigs.js
index f7020b6..64f2c37 100644
--- a/server/api/ipxeconfigs.js
+++ b/server/api/ipxeconfigs.js
@@ -116,6 +116,18 @@ router.putAsync('/:id/clients', async (req, res) => {
}
})
+router.putAsync('/:id/default', async (req, res) => {
+ if (!(req.params.id > 0)) return HttpResponse.invalidId().send(res)
+ const config = await db.config.findOne({ where: { id: req.params.id } })
+ if (config) {
+ await db.config.update({ isDefault: false }, { where: { isDefault: true } })
+ await config.update({ isDefault: true })
+ HttpResponse.success('set as default:', 'config', config.id).send(res)
+ } else {
+ HttpResponse.notFound(req.params.id).send(res)
+ }
+})
+
// ############################################################################
// ########################## DELETE requests ###############################
diff --git a/server/migrations/20190415232633-add-isdefault-config.js b/server/migrations/20190415232633-add-isdefault-config.js
new file mode 100644
index 0000000..364352f
--- /dev/null
+++ b/server/migrations/20190415232633-add-isdefault-config.js
@@ -0,0 +1,13 @@
+'use strict'
+module.exports = {
+ up: (queryInterface, Sequelize) => {
+ return queryInterface.addColumn('configs', 'isDefault', {
+ type: Sequelize.BOOLEAN,
+ defaultValue: false,
+ allowNull: false
+ })
+ },
+ down: (queryInterface, Sequelize) => {
+ return queryInterface.removeColumn('configs', 'isDefault')
+ }
+}
diff --git a/server/models/config.js b/server/models/config.js
index b8770e1..d8dd2de 100644
--- a/server/models/config.js
+++ b/server/models/config.js
@@ -11,7 +11,12 @@ module.exports = (sequelize, DataTypes) => {
description: DataTypes.STRING(2048),
defaultEntry: DataTypes.INTEGER,
timeout: DataTypes.INTEGER,
- script: DataTypes.STRING(4096)
+ script: DataTypes.STRING(4096),
+ isDefault: {
+ type: DataTypes.BOOLEAN,
+ defaultValue: false,
+ allowNull: false
+ }
}, {
timestamps: false
})