2022-12-26 21:10:50 +01:00
|
|
|
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
criteria: {
|
|
|
|
type: 'json',
|
2022-12-26 21:10:50 +01:00
|
|
|
custom: criteriaValidator,
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2020-12-13 23:17:12 +05:00
|
|
|
withDeleted: {
|
|
|
|
type: 'boolean',
|
|
|
|
defaultsTo: false,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2020-12-13 23:17:12 +05:00
|
|
|
const criteria = {};
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
if (_.isArray(inputs.criteria)) {
|
|
|
|
criteria.id = inputs.criteria;
|
|
|
|
} else if (_.isPlainObject(inputs.criteria)) {
|
|
|
|
Object.assign(criteria, inputs.criteria);
|
|
|
|
}
|
|
|
|
|
2020-12-13 23:17:12 +05:00
|
|
|
if (!inputs.withDeleted) {
|
|
|
|
criteria.deletedAt = null;
|
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return User.find(criteria).sort('id');
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|