fixes retrieval of next board cardnumber

This commit is contained in:
Kai Lehmann 2021-08-03 14:02:22 +02:00
parent 236b6c3552
commit e8522c323f

View file

@ -1065,8 +1065,23 @@ Boards.helpers({
},
getNextCardNumber() {
const boardCards = Cards.find({ boardId: this._id }).fetch();
return boardCards.length + 1;
const boardCards = Cards.find(
{
boardId: this._id
},
{
sort: { cardNumber: -1 },
limit: 1
}
).fetch();
// If no card is assigned to the board, return 1
if (!boardCards || boardCards.length === 0) {
return 1;
}
const maxCardNr = !!boardCards[0].cardNumber ? boardCards[0].cardNumber : 0;
return maxCardNr + 1;
},
cardsDueInBetween(start, end) {