Create a "like %" query from a JSON

Asked

Viewed 21 times

-1

Hello!

I am basically a list of users of an external API and I need to process this data in my queries.

I need to search by name as if I were doing a query in SQL but I am not able to handle the data. I managed to make him bring the user if pass the right name, then he finds but I want to pass only a part and bring all the data that had with those characters

service

findAll():Promise<any>{
    const URL = process.env.MICROSERVICE_ENDPOINT_ELB;
    const TOKEN = process.env.ELB_ACCESS_TOKEN;

    return this.httpService.get(`${URL}/api/users?access_token=${TOKEN}`).toPromise();
}

async getByName(nameFull: string): Promise<any> {
  const allUser = await this.findAll();


  console.log(allUser.data);
  console.log(nameFull);

  const users = allUser.users.filter((item) => item.name === nameFull);
  return users

}

Controller

@Get('name')
async getByName(@Query('name') queryData: string){
  const response =  await this.usersService.getByName(queryData);

  return response.data;
}

is being done in nestjs

passed me this lib https://doug-martin.github.io/nestjs-query/docs/concepts/queries but I couldn’t figure out how to use it in the system

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.