|
1 | 1 | # loopback-component-filter
|
2 | 2 |
|
3 |
| -[](https://travis-ci.com/loopback4/loopback-component-filter) |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
4 | 7 | [](https://app.fossa.com/projects/git%2Bgithub.com%2Floopback4%2Floopback-component-filter?ref=badge_shield)
|
5 |
| - |
6 |
| - |
7 |
| - |
8 |
| - |
9 | 8 |
|
10 | 9 | Using this simple extension you can filter models in repository level.
|
11 | 10 |
|
12 |
| ---- |
13 |
| - |
14 | 11 | ## Installation
|
15 | 12 |
|
| 13 | +Use the package manager [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) to install `loopback-component-filter`. |
| 14 | + |
16 | 15 | ```bash
|
17 | 16 | npm i --save loopback-component-filter
|
18 | 17 | ```
|
19 | 18 |
|
20 |
| ---- |
21 |
| - |
22 | 19 | ## Usage
|
23 | 20 |
|
24 |
| -### Filter Repository Mixin |
| 21 | +Follow these steps to add `Filter` extension to your loopback4 application: |
25 | 22 |
|
26 |
| -Change your repository parent class from `DefaultCrudRepository` to `FilterRepositoryMixin(configs)()` |
| 23 | +- Change your repository parent class from `DefaultCrudRepository` to `FilterRepositoryMixin(configs)()` |
27 | 24 |
|
28 |
| -#### Example |
| 25 | + ```ts |
| 26 | + // Old |
| 27 | + export class UserRepository extends DefaultCrudRepository< |
| 28 | + User, |
| 29 | + typeof User.prototype.id, |
| 30 | + UserRelations |
| 31 | + > { |
| 32 | + // ... |
| 33 | + } |
29 | 34 |
|
30 |
| -Change your repository from: |
| 35 | + // New |
| 36 | + import { FilterRepositoryMixin } from "loopback-component-filter"; |
31 | 37 |
|
32 |
| -```ts |
33 |
| -export class UserRepository extends DefaultCrudRepository< |
34 |
| - User, |
35 |
| - typeof User.prototype.id, |
36 |
| - UserRelations |
37 |
| -> { |
38 |
| - // ... |
39 |
| -} |
40 |
| -``` |
| 38 | + export class UserRepository extends FilterRepositoryMixin< |
| 39 | + User, |
| 40 | + typeof User.prototype.id, |
| 41 | + UserRelations |
| 42 | + >({ |
| 43 | + models: async (context, entities) => entities, |
| 44 | + where: async (context, where) => where, |
| 45 | + fields: async (context, fields) => fields, |
| 46 | + })<Constructor<DefaultCrudRepository<User, string, UserRelations>>>( |
| 47 | + DefaultCrudRepository |
| 48 | + ) { |
| 49 | + // ... |
| 50 | + } |
| 51 | + ``` |
41 | 52 |
|
42 |
| -To: |
43 |
| - |
44 |
| -```ts |
45 |
| -import { FilterRepositoryMixin } from "loopback-component-filter"; |
46 |
| - |
47 |
| -export class UserRepository extends FilterRepositoryMixin< |
48 |
| - User, |
49 |
| - typeof User.prototype.id, |
50 |
| - UserRelations |
51 |
| ->({ |
52 |
| - models: async (context, entities) => entities, |
53 |
| - where: async (context, where) => where, |
54 |
| - fields: async (context, fields) => fields, |
55 |
| -})<Constructor<DefaultCrudRepository<User, string, UserRelations>>>( |
56 |
| - DefaultCrudRepository |
57 |
| -) { |
58 |
| - // ... |
59 |
| -} |
60 |
| -``` |
61 |
| - |
62 |
| ---- |
| 53 | +## Contributing |
63 | 54 |
|
64 |
| -## Contributors |
| 55 | +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. |
65 | 56 |
|
66 |
| -- [KoLiBer](https://www.linkedin.com/in/mohammad-hosein-nemati-665b1813b/) |
| 57 | +Please make sure to update tests as appropriate. |
67 | 58 |
|
68 | 59 | ## License
|
69 | 60 |
|
70 |
| -This project is licensed under the [MIT license](LICENSE.md). |
| 61 | +This project is licensed under the [MIT](LICENSE.md). |
71 | 62 | Copyright (c) KoLiBer (koliberr136a1@gmail.com)
|
72 | 63 |
|
73 |
| - |
74 |
| -[](https://app.fossa.com/projects/git%2Bgithub.com%2Floopback4%2Floopback-component-filter?ref=badge_large) |
| 64 | +[](https://app.fossa.com/projects/git%2Bgithub.com%2Floopback4%2Floopback-component-filter?ref=badge_large) |
0 commit comments