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