mirror of
https://github.com/wekan/wekan.git
synced 2025-12-17 07:50:12 +01:00
Updated REST API Cards (markdown)
parent
5289dc69b0
commit
298dba02ec
1 changed files with 166 additions and 0 deletions
|
|
@ -60,3 +60,169 @@ The card's ID is returned in the format:
|
||||||
"_id": "W9m9YxQKT6zZrKzRW"
|
"_id": "W9m9YxQKT6zZrKzRW"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# In Wekan code
|
||||||
|
|
||||||
|
wekan/models/cards.js
|
||||||
|
```
|
||||||
|
JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards', function (req, res) {
|
||||||
|
const paramBoardId = req.params.boardId;
|
||||||
|
const paramListId = req.params.listId;
|
||||||
|
Authentication.checkBoardAccess(req.userId, paramBoardId);
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: Cards.find({boardId: paramBoardId, listId: paramListId, archived: false}).map(function (doc) {
|
||||||
|
return {
|
||||||
|
_id: doc._id,
|
||||||
|
title: doc.title,
|
||||||
|
description: doc.description,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards/:cardId', function (req, res) {
|
||||||
|
const paramBoardId = req.params.boardId;
|
||||||
|
const paramListId = req.params.listId;
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
Authentication.checkBoardAccess(req.userId, paramBoardId);
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: Cards.findOne({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false}),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('POST', '/api/boards/:boardId/lists/:listId/cards', function (req, res) {
|
||||||
|
Authentication.checkUserId(req.userId);
|
||||||
|
const paramBoardId = req.params.boardId;
|
||||||
|
const paramListId = req.params.listId;
|
||||||
|
const check = Users.findOne({_id: req.body.authorId});
|
||||||
|
const members = req.body.members || [req.body.authorId];
|
||||||
|
if (typeof check !== 'undefined') {
|
||||||
|
const id = Cards.direct.insert({
|
||||||
|
title: req.body.title,
|
||||||
|
boardId: paramBoardId,
|
||||||
|
listId: paramListId,
|
||||||
|
description: req.body.description,
|
||||||
|
userId: req.body.authorId,
|
||||||
|
swimlaneId: req.body.swimlaneId,
|
||||||
|
sort: 0,
|
||||||
|
members,
|
||||||
|
});
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
_id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const card = Cards.findOne({_id:id});
|
||||||
|
cardCreation(req.body.authorId, card);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 401,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('PUT', '/api/boards/:boardId/lists/:listId/cards/:cardId', function (req, res) {
|
||||||
|
Authentication.checkUserId(req.userId);
|
||||||
|
const paramBoardId = req.params.boardId;
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
const paramListId = req.params.listId;
|
||||||
|
|
||||||
|
if (req.body.hasOwnProperty('title')) {
|
||||||
|
const newTitle = req.body.title;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {title: newTitle}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('listId')) {
|
||||||
|
const newParamListId = req.body.listId;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {listId: newParamListId}});
|
||||||
|
|
||||||
|
const card = Cards.findOne({_id: paramCardId} );
|
||||||
|
cardMove(req.body.authorId, card, {fieldName: 'listId'}, paramListId);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('description')) {
|
||||||
|
const newDescription = req.body.description;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {description: newDescription}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('labelIds')) {
|
||||||
|
const newlabelIds = req.body.labelIds;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {labelIds: newlabelIds}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('requestedBy')) {
|
||||||
|
const newrequestedBy = req.body.requestedBy;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {requestedBy: newrequestedBy}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('assignedBy')) {
|
||||||
|
const newassignedBy = req.body.assignedBy;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {assignedBy: newassignedBy}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('receivedAt')) {
|
||||||
|
const newreceivedAt = req.body.receivedAt;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {receivedAt: newreceivedAt}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('startAt')) {
|
||||||
|
const newstartAt = req.body.startAt;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {startAt: newstartAt}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('dueAt')) {
|
||||||
|
const newdueAt = req.body.dueAt;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {dueAt: newdueAt}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('endAt')) {
|
||||||
|
const newendAt = req.body.endAt;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {endAt: newendAt}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('spentTime')) {
|
||||||
|
const newspentTime = req.body.spentTime;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {spentTime: newspentTime}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('isOverTime')) {
|
||||||
|
const newisOverTime = req.body.isOverTime;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {isOverTime: newisOverTime}});
|
||||||
|
}
|
||||||
|
if (req.body.hasOwnProperty('customFields')) {
|
||||||
|
const newcustomFields = req.body.customFields;
|
||||||
|
Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false},
|
||||||
|
{$set: {customFields: newcustomFields}});
|
||||||
|
}
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
_id: paramCardId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
JsonRoutes.add('DELETE', '/api/boards/:boardId/lists/:listId/cards/:cardId', function (req, res) {
|
||||||
|
Authentication.checkUserId(req.userId);
|
||||||
|
const paramBoardId = req.params.boardId;
|
||||||
|
const paramListId = req.params.listId;
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
|
||||||
|
Cards.direct.remove({_id: paramCardId, listId: paramListId, boardId: paramBoardId});
|
||||||
|
const card = Cards.find({_id: paramCardId} );
|
||||||
|
cardRemover(req.body.authorId, card);
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
_id: paramCardId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
Loading…
Add table
Add a link
Reference in a new issue