nestjs-query icon indicating copy to clipboard operation
nestjs-query copied to clipboard

Generic QueryService Docs

Open Distortedlogic opened this issue 3 years ago • 1 comments

📚 Documentation

we have docs on how to create a custom query service. https://doug-martin.github.io/nestjs-query/docs/persistence/typeorm/custom-service

But the docs do not address how to create a generic custom query service to use as a base for all other custom query services. The only issue that I believe necessarily needs to be addressed is how to handle the @QueryService decorator, since in the generic case, the generic type for the entity cannot be placed in the decorator. An example would be great, instead of trail-error.

Distortedlogic avatar Jan 23 '22 12:01 Distortedlogic

Here is what I am currently goina try

export interface IBaseQueryService<T> extends TypeOrmQueryService<T> {
  myFunc: ()=> void
}

export function BaseQueryService<TEntity>(classRef: Type<TEntity>): Type<IBaseQueryService<TEntity>> {
  class BaseQueryServiceType<TEntity> extends TypeOrmQueryService<TEntity> {
    constructor(@InjectRepository(classRef) repo: Repository<TEntity>) {
      super(repo);
    }

    myFunc(){
        return;
    }
  }

  return BaseQueryServiceType as Type<IBaseQueryService<TEntity>>;
}

trying to use @QueryService(classRef) on BaseQueryServiceType gives type error

Distortedlogic avatar Jan 23 '22 13:01 Distortedlogic