Skip to content

Commit 14d3735

Browse files
arnoldtklTEO KIAT LOONG
andauthored
docs: Update hooks documentation - setField (#683)
* refactor(set-field hooks): Handle 'as' field startsWith data and type array To handle multi: true , create method. The data is in array format. Add logic to loop and apply the 'as' field to each array of object. * refactor(set-field): revert changes, update documentation * docs(setField): Update note for the setField When dealing with data that is array type, setField result may not working as expected result. Co-authored-by: TEO KIAT LOONG <[email protected]>
1 parent 846dcfa commit 14d3735

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

docs/hooks.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Runs a series of hooks which mutate context.dispatch.
5050
|before|after|methods|multi|details|
5151
|---|---|---|---|---|
5252
|yes|yes|all|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/act-on-dispatch.ts)|
53-
53+
5454

5555
- **Arguments**
5656

@@ -540,7 +540,7 @@ Join related records.
540540
- **Example using Feathers services**
541541
542542
<p class="tip">The services in all these examples are assumed, for simplicity, to have pagination disabled. You will have to decide when to use `paginate: false` in your code.</p>
543-
543+
544544
``` js
545545
// project/src/services/posts/posts.hooks.js
546546
const { fastJoin } = require('feathers-hooks-common');
@@ -956,7 +956,7 @@ Execute one array of hooks or another based on a sync or async predicate.
956956
|before|after|methods|multi|details|
957957
|---|---|---|---|---|
958958
|yes|yes|all|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/iff-else.ts)|
959-
959+
960960
- **Arguments**
961961
- `{Function} predicate`
962962
- `{Array< Functions >} hookFuncsTrue`
@@ -1069,7 +1069,7 @@ Keep certain fields in the query object, deleting the rest.
10691069
|before|after|methods|multi|details|
10701070
|---|---|---|---|---|
10711071
|yes|yes|all|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/keep-query.ts)|
1072-
1072+
10731073
> __Note:__ The keepQuery hook will remove any fields not specified even if the service is being called from the server. You may want to condition the hook to run only for external transports, e.g. `iff(isProvider('external'), keepQuery(...))`.
10741074
10751075
- Arguments
@@ -1103,7 +1103,7 @@ Keep certain fields in a nested array inside the query object, deleting the rest
11031103
|before|after|methods|multi|details|
11041104
|---|---|---|---|---|
11051105
|yes|yes|all|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/keep-query-in-array.ts)|
1106-
1106+
11071107
> __Note:__ The keepQueryInArray hook will remove any fields not specified even if the service is being called from the server. You may want to condition the hook to run only for external transports, e.g. `iff(isProvider('external'), keepQueryInArray(...))`.
11081108
11091109
- Arguments
@@ -1148,7 +1148,7 @@ Convert certain field values to lower case.
11481148
|---|---|---|---|---|
11491149
|yes||create, update, patch|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/lower-case.ts)|
11501150
||yes|all|||
1151-
1151+
11521152
11531153
- Arguments
11541154
- `{Array < String >} fieldNames`
@@ -1181,7 +1181,7 @@ Wrap MongoDB foreign keys in ObjectID.
11811181
|before|after|methods|multi|details|
11821182
|---|---|---|---|---|
11831183
|yes|no|all|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/mongo-keys.ts)|
1184-
1184+
11851185
- **Arguments**
11861186
11871187
- `{Function} ObjectID`
@@ -1239,7 +1239,7 @@ Pass `context.params` from client to server. Server hook.
12391239
|before|after|methods|multi|details|
12401240
|---|---|---|---|---|
12411241
|yes|yes|all|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/params-from-client.ts)|
1242-
1242+
12431243
- **Arguments**
12441244
12451245
- `{Array< String > | String} whitelist`
@@ -1291,7 +1291,7 @@ Join related records.
12911291
|before|after|methods|multi|details|
12921292
|---|---|---|---|---|
12931293
|yes|yes|all|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/populate.ts)|
1294-
1294+
12951295
> `fastJoin` is preferred over using `populate`.
12961296
12971297
- **Arguments**
@@ -1511,7 +1511,7 @@ Prevent patch service calls from changing certain fields.
15111511
|before|after|methods|multi|details|
15121512
|---|---|---|---|---|
15131513
|yes|no|patch|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/prevent-changes.ts)|
1514-
1514+
15151515
- **Arguments**
15161516
15171517
- `{Boolean} ifThrow`
@@ -1546,7 +1546,7 @@ Check selected fields exist and are not falsey. Numeric 0 is acceptable.
15461546
|before|after|methods|multi|details|
15471547
|---|---|---|---|---|
15481548
|yes|no|create, update, patch|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/required.ts)|
1549-
1549+
15501550
- Arguments
15511551
- `{Array < String >} fieldNames`
15521552
@@ -1697,6 +1697,8 @@ The `setField` hook allows to set a field on the hook context based on the value
16971697
16981698
> __Important:__ This hook should be used after the [authenticate hook](https://docs.feathersjs.com/api/authentication/hook.html#authenticate-options) when accessing user fields (from `params.user`).
16991699
1700+
__Note:__ When the service enable `multi:true` and `data` is an array data type, this hook may working to an unexpected result
1701+
17001702
### Examples
17011703
17021704
Limit all external access of the `users` service to the authenticated user:
@@ -1814,7 +1816,7 @@ Set slugs in URL, e.g. /stores/:storeId.
18141816
|before|after|methods|multi|details|
18151817
|---|---|---|---|---|
18161818
|yes|yes|all|yes|[source](https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/master/src/hooks/set-slug.ts)|
1817-
1819+
18181820
- **Arguments**
18191821
- `{String} slug`
18201822
- `{String} [ fieldName ]`

0 commit comments

Comments
 (0)