1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/server/api/helpers/boards/get-cards.js

42 lines
903 B
JavaScript
Raw Normal View History

const LIMIT = 10;
2019-08-31 04:07:25 +05:00
module.exports = {
inputs: {
recordOrIdOrIds: {
type: 'ref',
custom: (value) => _.isObjectLike(value) || _.isString(value) || _.every(value, _.isString),
required: true,
},
beforeId: {
type: 'string',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs) {
const criteria = {};
let sort;
let limit;
if (_.isObjectLike(inputs.recordOrIdOrIds)) {
criteria.boardId = inputs.recordOrIdOrIds.id;
if (inputs.recordOrIdOrIds.type === Board.Types.KANBAN) {
sort = 'position';
} else if (inputs.recordOrIdOrIds.type === Board.Types.COLLECTION) {
if (inputs.beforeId) {
criteria.id = {
'<': inputs.beforeId,
};
}
limit = LIMIT;
}
} else {
criteria.boardId = inputs.recordOrIdOrIds;
}
return sails.helpers.cards.getMany(criteria, sort, limit);
},
2019-08-31 04:07:25 +05:00
};