Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem to use a partial data info in where filter #11

Open
flaviofagundes opened this issue Dec 22, 2017 · 2 comments
Open

Problem to use a partial data info in where filter #11

flaviofagundes opened this issue Dec 22, 2017 · 2 comments

Comments

@flaviofagundes
Copy link

I suggest the code block below to add 'like' statement:

if (query['where'] ) { var json = query['where']; query['where'] = {}; Object.keys(json).forEach(function(key) { query['where'][key] = { "like" : json[key], "options":"i" } ; }); }

in src/index.js after

query['where'] = {...params.filter}; //line 41

@flaviofagundes
Copy link
Author

In MySql i have to use

if (query['where']) { var json = query['where']; query['where'] = {}; Object.keys(json).forEach(function (key) { query['where'][key] = { "regexp": '/^'+json[key]+'/i' }; }); }

@Neira1991
Copy link

Neira1991 commented Mar 17, 2018

Hola, en Admin on rest tu puedes decorar tu restClient con un filtro


const addFiltersCapabilities = requestHandler => (type, resource, params) => {

  switch (type) {
    case GET_LIST:
      if (
        resource === 'Notices' &&
        params.filter.name !== undefined &&
        type === 'GET_LIST'
      ) {
        return requestHandler('GET_LIST', 'Notices', {
          pagination: {},
          sort: {},
          filter: { name: { regexp: `.*${params.filter.name}.*` } }
        });
      }
      return requestHandler(type, resource, params);
    default:
      return requestHandler(type, resource, params);
  }
};
export default addFiltersCapabilities;

so

<Admin
   restClient={addFiltersCapabilities(loopbackRestClient(API_URL))}
 >

espero sirva de ayuda

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants