Using this simple extension you can filter models in repository level.
Use the package manager npm to install loopback-component-filter
.
npm i --save loopback-component-filter
Follow these steps to add Filter
extension to your loopback4 application:
-
Change your repository parent class from
DefaultCrudRepository
toFilterRepositoryMixin(configs)()
// Old export class UserRepository extends DefaultCrudRepository< User, typeof User.prototype.id, UserRelations > { // ... } // New import { FilterRepositoryMixin } from "loopback-component-filter"; export class UserRepository extends FilterRepositoryMixin< User, typeof User.prototype.id, UserRelations >({ models: async (context, entities) => entities, where: async (context, where) => where, fields: async (context, fields) => fields, })<Constructor<DefaultCrudRepository<User, string, UserRelations>>>( DefaultCrudRepository ) { // ... }
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
This project is licensed under the MIT.
Copyright (c) KoLiBer (koliberr136a1@gmail.com)