nestjs-query
nestjs-query copied to clipboard
Generic QueryService Docs
📚 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.
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