2020-08-04 01:32:46 +05:00
|
|
|
const LIMIT = 10;
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
2020-08-04 01:32:46 +05:00
|
|
|
recordOrId: {
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
async fn(inputs, exits) {
|
2020-08-04 01:32:46 +05:00
|
|
|
const criteria = {};
|
|
|
|
|
|
|
|
let sort;
|
|
|
|
let limit;
|
|
|
|
|
|
|
|
if (_.isObjectLike(inputs.recordOrId)) {
|
|
|
|
criteria.boardId = inputs.recordOrId.id;
|
|
|
|
|
|
|
|
if (inputs.recordOrId.type === 'kanban') {
|
|
|
|
sort = 'position';
|
|
|
|
} else if (inputs.recordOrId.type === 'collection') {
|
|
|
|
if (inputs.beforeId) {
|
|
|
|
criteria.id = {
|
|
|
|
'<': inputs.beforeId,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
limit = LIMIT;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
criteria.boardId = inputs.recordOrId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const cards = await sails.helpers.getCards(criteria, sort, limit);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
return exits.success(cards);
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|