summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorNET\faguet <guillaume.faguet@avisto.com>2018-05-07 13:32:33 +0200
committerNET\faguet <guillaume.faguet@avisto.com>2018-05-07 13:32:33 +0200
commit1cb8a6e7fe3c3ba4bf2bc5f5a576d2ed46750fb0 (patch)
tree858e67bf90d55b5b6138be305290f4db6af558b6 /models
parent5e109de8d5bf9d9d274cda031618b11d01937e9c (diff)
downloadwekan-1cb8a6e7fe3c3ba4bf2bc5f5a576d2ed46750fb0.tar.gz
wekan-1cb8a6e7fe3c3ba4bf2bc5f5a576d2ed46750fb0.tar.bz2
wekan-1cb8a6e7fe3c3ba4bf2bc5f5a576d2ed46750fb0.zip
Add a new API route to create a new label in a given board
Diffstat (limited to 'models')
-rw-r--r--models/boards.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/models/boards.js b/models/boards.js
index 3e05b499..da50adc7 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -719,4 +719,33 @@ if (Meteor.isServer) {
});
}
});
+
+ JsonRoutes.add('PUT', '/api/boards/:id/labels', function (req, res) {
+ Authentication.checkUserId(req.userId);
+ const id = req.params.id;
+ try {
+ if (req.body.hasOwnProperty('label')) {
+ const board = Boards.findOne({ _id: id });
+ const color = req.body.label.color;
+ const name = req.body.label.name;
+ const labelId = Random.id(6);
+ if (!board.getLabel(name, color)) {
+ Boards.direct.update({ _id: id }, { $push: { labels: { "_id": labelId, "name": name, "color": color } } });
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: labelId,
+ });
+ } else {
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ });
+ }
+ }
+ }
+ catch (error) {
+ JsonRoutes.sendResult(res, {
+ data: error,
+ });
+ }
+ });
}