filter tickets

This commit is contained in:
Daniel Herrero 2018-03-14 13:59:01 +01:00
parent 82949b42b5
commit e6a8b34fe4
3 changed files with 44 additions and 1 deletions

View File

@ -1,4 +1,4 @@
<mg-ajax path="/client/api/Clients/filter" options="vnIndexNonAuto"></mg-ajax>
<mg-ajax path="/ticket/api/Tickets/filter" options="vnIndexNonAuto"></mg-ajax>
<div margin-medium>
<div class="vn-list">
<vn-card>

View File

@ -0,0 +1,42 @@
module.exports = Self => {
Self.installMethod('filter', filterParams);
function filterParams(params) {
let filters = {
where: {},
skip: (params.page - 1) * params.size,
limit: params.size,
order: params.order || 'created DESC'
};
delete params.page;
delete params.size;
delete params.order;
if (params.search) {
filters.where.and = [
{
or: [
{id: params.search},
{name: {regexp: params.search}}
]
}
];
delete params.search;
}
Object.keys(params).forEach(
key => {
if (filters.where.and) {
let filter = {};
filter[key] = (key === 'nickname') ? {regexp: params[key]} : params[key];
filters.where.and.push(filter);
} else {
filters.where[key] = (key === 'nickname') ? {regexp: params[key]} : params[key];
}
}
);
return filters;
}
};

View File

@ -2,4 +2,5 @@
module.exports = function(Self) {
require('../methods/ticket/change-time.js')(Self);
require('../methods/ticket/change-worker.js')(Self);
require('../methods/ticket/filter.js')(Self);
};