Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const composeFilter = (paramsFilter) => {
const flatFilter = fetchUtils.flattenObject(paramsFilter)
const filter = Object.keys(flatFilter).map(key => {
const splitKey = key.split('||');
let ops = splitKey[1] ? splitKey[1] : 'cont';
let field = splitKey[0];
// code below allows multifield filters in react admin (date range for example). Here is an example:
//
//
//
//
//
if (field.indexOf('_') == 0 && field.indexOf('.') > -1) {
field = field.split(/\.(.+)/)[1];
}
return field + '||' + ops + '||' + flatFilter[key];
})
return filter;
const composeFilter = (paramsFilter) => {
if (paramsFilter === '' || (typeof paramsFilter.q !== 'undefined' && paramsFilter.q === '')) {
paramsFilter = {}
}
const flatFilter = fetchUtils.flattenObject(paramsFilter);
const filter = Object.keys(flatFilter).map(key => {
const splitKey = key.split('||');
const ops = splitKey[1] ? splitKey[1] : 'cont';
let field = splitKey[0];
if (field.indexOf('_') === 0 && field.indexOf('.') > -1) {
field = field.split(/\.(.+)/)[1];
}
return { field, operator: ops, value: flatFilter[key] };
});
return filter;
};
query[params.target] = params.id
}
case GET_LIST:
const {page, perPage} = params.pagination || {}
const {field, order} = params.sort || {}
const sortKey = `$sort[${field === 'id' ? idKey : field}]`
dbg('field=%o, sort-key=%o', field, sortKey)
let sortVal = order === 'DESC' ? -1 : 1
if (perPage && page) {
query['$limit'] = perPage
query['$skip'] = perPage * (page - 1)
}
if (order) {
query[sortKey] = JSON.stringify(sortVal)
}
Object.assign(query, fetchUtils.flattenObject(params.filter));
dbg('query=%o', query)
return service.find({query})
case GET_ONE:
return service.get(params.id)
case UPDATE:
if (usePatch) {
const data = params.previousData ? diff(params.previousData, params.data) : params.data
return service.patch(params.id, data)
}
return service.update(params.id, params.data)
case CREATE:
return service.create(params.data)
case DELETE:
return service.remove(params.id)
default:
throw new Error(`Unsupported FeathersJS restClient action type ${type}`)
const convertDataRequestToHTTP = (apiUrl, type, resource, params) => {
let url = "";
const options = {
headers: new Headers({
Accept: "application/json"
})
};
switch (type) {
case GET_LIST: {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
let _field = field === "id" ? "_id" : field;
const query = {
...fetchUtils.flattenObject(params.filter),
sort: order === "DESC" ? `-${_field}` : _field,
page: page,
limit: perPage
};
url = `${apiUrl}/${resource}?${stringify(query)}`;
break;
}
case GET_ONE:
url = `${apiUrl}/${resource}/${params.id}`;
break;
case CREATE:
url = `${apiUrl}/${resource}`;
options.method = "POST";
options.body = JSON.stringify(params.data);
break;
case UPDATE:
_sort: field,
_order: order,
_start: (page - 1) * perPage,
_end: page * perPage,
};
url = `${apiUrl}/${resource}?${stringify(query)}`;
break;
}
case GET_ONE:
url = `${apiUrl}/${resource}/${params.id}`;
break;
case GET_MANY_REFERENCE: {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
const query = {
...fetchUtils.flattenObject(params.filter),
[params.target]: params.id,
_sort: field,
_order: order,
_start: (page - 1) * perPage,
_end: page * perPage,
};
url = `${apiUrl}/${resource}?${stringify(query)}`;
break;
}
case UPDATE:
url = `${apiUrl}/${resource}/${params.id}`;
options.method = 'PUT';
options.body = JSON.stringify(params.data);
break;
case CREATE:
url = `${apiUrl}/${resource}`;