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

Generic QueryService Docs #1515

Open
Distortedlogic opened this issue Jan 23, 2022 · 1 comment
Open

Generic QueryService Docs #1515

Distortedlogic opened this issue Jan 23, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@Distortedlogic
Copy link

📚 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 Distortedlogic added the documentation Improvements or additions to documentation label Jan 23, 2022
@Distortedlogic
Copy link
Author

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

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

No branches or pull requests

1 participant