mirror of
https://github.com/wekan/wekan.git
synced 2025-12-21 01:40:13 +01:00
add rest api for checklist and card comment
This commit is contained in:
parent
8267b5a01c
commit
d9c0825d5f
2 changed files with 139 additions and 15 deletions
|
|
@ -80,3 +80,61 @@ if (Meteor.isServer) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CARD COMMENT REST API
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/comments', function (req, res, next) {
|
||||||
|
const paramBoardId = req.params.boardId;
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: CardComments.find({ boardId: paramBoardId, cardId: paramCardId}).map(function (doc) {
|
||||||
|
return {
|
||||||
|
_id: doc._id,
|
||||||
|
comment: doc.text,
|
||||||
|
authorId: doc.userId,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/comments/:commentId', function (req, res, next) {
|
||||||
|
const paramBoardId = req.params.boardId;
|
||||||
|
const paramCommentId = req.params.commentId;
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: CardComments.findOne({ _id: paramCommentId, cardId: paramCardId, boardId: paramBoardId }),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('POST', '/api/boards/:boardId/cards/:cardId/comments', function (req, res, next) {
|
||||||
|
const paramBoardId = req.params.boardId;
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
const id = CardComments.insert({
|
||||||
|
userId: req.body.authorId,
|
||||||
|
text: req.body.comment,
|
||||||
|
cardId: paramCardId,
|
||||||
|
boardId: paramBoardId,
|
||||||
|
});
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
_id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('DELETE', '/api/boards/:boardId/cards/:cardId/comments/:commentId', function (req, res, next) {
|
||||||
|
const paramBoardId = req.params.boardId;
|
||||||
|
const paramCommentId = req.params.commentId;
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
CardComments.remove({ _id: paramCommentId, cardId: paramCardId, boardId: paramBoardId });
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
_id: paramCardId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,22 +28,29 @@ Checklists.attachSchema(new SimpleSchema({
|
||||||
createdAt: {
|
createdAt: {
|
||||||
type: Date,
|
type: Date,
|
||||||
denyUpdate: false,
|
denyUpdate: false,
|
||||||
|
autoValue() { // eslint-disable-line consistent-return
|
||||||
|
if (this.isInsert) {
|
||||||
|
return new Date();
|
||||||
|
} else {
|
||||||
|
this.unset();
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Checklists.helpers({
|
Checklists.helpers({
|
||||||
itemCount () {
|
itemCount() {
|
||||||
return this.items.length;
|
return this.items.length;
|
||||||
},
|
},
|
||||||
finishedCount () {
|
finishedCount() {
|
||||||
return this.items.filter((item) => {
|
return this.items.filter((item) => {
|
||||||
return item.isFinished;
|
return item.isFinished;
|
||||||
}).length;
|
}).length;
|
||||||
},
|
},
|
||||||
isFinished () {
|
isFinished() {
|
||||||
return 0 !== this.itemCount() && this.itemCount() === this.finishedCount();
|
return 0 !== this.itemCount() && this.itemCount() === this.finishedCount();
|
||||||
},
|
},
|
||||||
getItem (_id) {
|
getItem(_id) {
|
||||||
return _.findWhere(this.items, { _id });
|
return _.findWhere(this.items, { _id });
|
||||||
},
|
},
|
||||||
itemIndex(itemId) {
|
itemIndex(itemId) {
|
||||||
|
|
@ -73,17 +80,17 @@ Checklists.before.insert((userId, doc) => {
|
||||||
|
|
||||||
Checklists.mutations({
|
Checklists.mutations({
|
||||||
//for checklist itself
|
//for checklist itself
|
||||||
setTitle(title){
|
setTitle(title) {
|
||||||
return { $set: { title }};
|
return { $set: { title } };
|
||||||
},
|
},
|
||||||
//for items in checklist
|
//for items in checklist
|
||||||
addItem(title) {
|
addItem(title) {
|
||||||
const itemCount = this.itemCount();
|
const itemCount = this.itemCount();
|
||||||
const _id = `${this._id}${itemCount}`;
|
const _id = `${this._id}${itemCount}`;
|
||||||
return { $addToSet: {items: {_id, title, isFinished: false}} };
|
return { $addToSet: { items: { _id, title, isFinished: false } } };
|
||||||
},
|
},
|
||||||
removeItem(itemId) {
|
removeItem(itemId) {
|
||||||
return {$pull: {items: {_id : itemId}}};
|
return { $pull: { items: { _id: itemId } } };
|
||||||
},
|
},
|
||||||
editItem(itemId, title) {
|
editItem(itemId, title) {
|
||||||
if (this.getItem(itemId)) {
|
if (this.getItem(itemId)) {
|
||||||
|
|
@ -150,13 +157,13 @@ if (Meteor.isServer) {
|
||||||
//TODO: so there will be no activity for adding item into checklist, maybe will be implemented in the future.
|
//TODO: so there will be no activity for adding item into checklist, maybe will be implemented in the future.
|
||||||
// Checklists.after.update((userId, doc) => {
|
// Checklists.after.update((userId, doc) => {
|
||||||
// console.log('update:', doc)
|
// console.log('update:', doc)
|
||||||
// Activities.insert({
|
// Activities.insert({
|
||||||
// userId,
|
// userId,
|
||||||
// activityType: 'addChecklist',
|
// activityType: 'addChecklist',
|
||||||
// boardId: doc.boardId,
|
// boardId: doc.boardId,
|
||||||
// cardId: doc.cardId,
|
// cardId: doc.cardId,
|
||||||
// checklistId: doc._id,
|
// checklistId: doc._id,
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
|
|
||||||
Checklists.before.remove((userId, doc) => {
|
Checklists.before.remove((userId, doc) => {
|
||||||
|
|
@ -166,3 +173,62 @@ if (Meteor.isServer) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CARD COMMENT REST API
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/checklists', function (req, res, next) {
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: Checklists.find({ cardId: paramCardId }).map(function (doc) {
|
||||||
|
return {
|
||||||
|
_id: doc._id,
|
||||||
|
title: doc.title,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/checklists/:checklistId', function (req, res, next) {
|
||||||
|
const paramChecklistId = req.params.checklistId;
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: Checklists.findOne({ _id: paramChecklistId, cardId: paramCardId }),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('POST', '/api/boards/:boardId/cards/:cardId/checklists', function (req, res, next) {
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
|
||||||
|
const checklistToSend = {};
|
||||||
|
checklistToSend.cardId = paramCardId;
|
||||||
|
checklistToSend.title = req.body.title;
|
||||||
|
checklistToSend.items = [];
|
||||||
|
const id = Checklists.insert(checklistToSend);
|
||||||
|
const checklist = Checklists.findOne({_id: id});
|
||||||
|
req.body.items.forEach(function (item) {
|
||||||
|
checklist.addItem(item);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
_id: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
JsonRoutes.add('DELETE', '/api/boards/:boardId/cards/:cardId/checklists/:checklistId', function (req, res, next) {
|
||||||
|
const paramCommentId = req.params.commentId;
|
||||||
|
const paramCardId = req.params.cardId;
|
||||||
|
Checklists.remove({ _id: paramCommentId, cardId: paramCardId });
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
_id: paramCardId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue