mirror of
https://github.com/wekan/wekan.git
synced 2025-12-20 17:30:13 +01:00
models: boards: add PUT members entry point
Allows to change the members from the API.
This commit is contained in:
parent
33d4ad76ca
commit
f61942e5cb
1 changed files with 32 additions and 0 deletions
|
|
@ -276,6 +276,10 @@ Boards.helpers({
|
||||||
return Users.find({ _id: { $in: _.pluck(this.members, 'userId') } });
|
return Users.find({ _id: { $in: _.pluck(this.members, 'userId') } });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getMember(id) {
|
||||||
|
return _.findWhere(this.members, { userId: id });
|
||||||
|
},
|
||||||
|
|
||||||
getLabel(name, color) {
|
getLabel(name, color) {
|
||||||
return _.findWhere(this.labels, { name, color });
|
return _.findWhere(this.labels, { name, color });
|
||||||
},
|
},
|
||||||
|
|
@ -841,6 +845,34 @@ if (Meteor.isServer) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('PUT', '/api/boards/:boardId/members', function (req, res) {
|
||||||
|
Authentication.checkUserId(req.userId);
|
||||||
|
try {
|
||||||
|
const boardId = req.params.boardId;
|
||||||
|
const board = Boards.findOne({ _id: boardId });
|
||||||
|
const userId = req.body.userId;
|
||||||
|
const user = Users.findOne({ _id: userId });
|
||||||
|
|
||||||
|
if (!board.getMember(userId)) {
|
||||||
|
user.addInvite(boardId);
|
||||||
|
board.addMember(userId);
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: id,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
data: error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
JsonRoutes.add('POST', '/api/boards', function (req, res) {
|
JsonRoutes.add('POST', '/api/boards', function (req, res) {
|
||||||
try {
|
try {
|
||||||
Authentication.checkUserId(req.userId);
|
Authentication.checkUserId(req.userId);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue