TriPSs/nestjs-query

TypeORM - Simple-array doesn't work

Closed this issue · 6 comments

Hello,

I want to use FilterableField with a simple-array (typeorm), exemple :

  @FilterableField(() => [RolesEnum])
  @Column({
    type: 'simple-array',
    enum: RolesEnum,
    name: 'roles',
    default: [RolesEnum.CUSTOMER],
  })
  roles: RolesEnum[];

But i have this error :
Error: Unable to create filter comparison for [{"DEVELOPER":"DEVELOPER","ADMIN":"ADMIN","CUSTOMER":"CUSTOMER"}].

Same error when changing from [RolesEnum] to [String]

If you have a solution for me, I'm interested, thank you!

Thank's !

PS : Is it possible to create a typeorm querybuilder to customize the query as I see fit?
I want to use postgis SQL statements

Interesting, I have the feeling it is because everything "array" is seen as a relation and @FilterableField does not handle that, could you add this case to an example (basic for example)? Than I can check it out.

Thank you for your responsiveness and for explaining it to me. It's a project with users who can have multiple roles in the app: artisan, client, admin, etc. So, I use the role to handle this, and I put it in an array to simplify the app and easily include it in the JWT.

When I want to retrieve a list of users, I use

  @Query(() => UserConnection, {
    nullable: true,
    description: `Liste des artisans`,
  })
  getArtisans(
    @Args() query: UserQuery
  ): Promise<ConnectionType<User>> {
    return this.usersService.indexArtisans(query);
  }
  async indexArtisans(data: UserQuery) {
    return UserConnection.createFromPromise(
      (q) => this.usersQueryService.query(q),
      { ...data, ...{ filter: data.filter } },
      (filter) => this.usersQueryService.count(filter)
    );
  }

But I encounter the aforementioned error.

I would have liked to use a query builder and be able to utilize your GraphQL return because it's very convenient, but I couldn't retrieve a query builder with your library, or at least I couldn't find one. 😬

Just now see this part:

PS : Is it possible to create a typeorm querybuilder to customize the query as I see fit?
I want to use postgis SQL statements

Yes this is possible, when you create your own service you can pass FilterQueryBuilder inside the constructor opts, you could create your own that extends the default and overwrite the things you want.

Can you give me an example ?

Here are some docs on how to create a custom service, in the constructor:

super(repo, {
      filterQueryBuilder: CustomFilterQueryBuilder
})

Closing as it's (I think?) the same as #233