From 543892daa62e79569d8d50083b28f6097dab3340 Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Thu, 18 Apr 2024 15:10:54 +0100 Subject: [PATCH 1/2] feat(orm): change isHidden docs --- docs/orm/annotations.mdx | 16 +++++++++++++++- docs/orm/query-builder.mdx | 22 +++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/docs/orm/annotations.mdx b/docs/orm/annotations.mdx index c39c10cb..f42f3396 100644 --- a/docs/orm/annotations.mdx +++ b/docs/orm/annotations.mdx @@ -118,13 +118,27 @@ public id: number > Default: `false` -Set if the column should be hidden when retrieving it from database: +Set if the field should be hidden when executing the +`toJSON()` method of the model: ```typescript @Column({ isHidden: true }) public password: string ``` +:::tip + +To force return hidden fields in `toJSON()` calls, +use the `withHidden` option: + +```typescript +const flight = await Flight.find() + +const flightJson = flight.toJSON({ withHidden: true }) +``` + +::: + ### `isUnique` > Default: `false` diff --git a/docs/orm/query-builder.mdx b/docs/orm/query-builder.mdx index 17fec944..b429e246 100644 --- a/docs/orm/query-builder.mdx +++ b/docs/orm/query-builder.mdx @@ -58,7 +58,7 @@ You may use any of these methods when writing your model queries. ::: -### Hiding fields +### Hidding fields Sometimes you might need to hide some sensitive field from your model queries, to do so, you can set the `isHidden` property to true in your @@ -75,29 +75,21 @@ export class User extends BaseModel { } ``` -Everytime you call the `query()` method of your models, Athenna will -automatically select all the columns from your model but never the -ones where the `isHidden` property is true. +Everytime you call the `toJSON()` method of your models, Athenna will +ignore all the hidden columns from your model and return the rest. #### Retrieve hidden fields Is possible to bypass the `isHidden` validation using the -`select()` method from the query builder: +`withHidden` option of the `toJSON()` method: ```typescript -const { password } = await User.query() +const user = await User.query() .select('id') - .select('password') 👈 + .select('password') .find() -``` - -If you wish to get all the hidden fields for a specify use case, you -can use the `withHidden()` method: -```typescript -const { password } = await User.query() - .withHidden() - .find() +const { password } = user.toJSON({ withHidden: true }) 👈 ``` ## Collections From 5dcad8942f99915e3155460a3544d573449aa30d Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Wed, 8 May 2024 10:23:24 +0100 Subject: [PATCH 2/2] fix(ctx): adjust default value examples --- docs/rest-api-application/request-context.mdx | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/rest-api-application/request-context.mdx b/docs/rest-api-application/request-context.mdx index c44afdca..29f62c72 100644 --- a/docs/rest-api-application/request-context.mdx +++ b/docs/rest-api-application/request-context.mdx @@ -146,11 +146,11 @@ Retrieve only one value per call from the request body: Route.post('/welcome/:id', ({ request }) => { const defaultValue = 'defaultValue' - console.log(request.input('hello'), 'found') // 'world' - console.log(request.input('not-found'), defaultValue) // 'defaultValue' + console.log(request.input('hello', 'found')) // 'world' + console.log(request.input('not-found', defaultValue)) // 'defaultValue' - console.log(request.payload('hello'), defaultValue) // 'world' - console.log(request.payload('not-found'), defaultValue) // 'defaultValue' + console.log(request.payload('hello', defaultValue)) // 'world' + console.log(request.payload('not-found', defaultValue)) // 'defaultValue' /*....*/ }) @@ -203,14 +203,14 @@ value if the first argument key doesn't exist: Route.post('/welcome/:id', ({ request }) => { const defaultValue = 'defaultValue' - console.log(request.param('id'), defaultValue) // '1' - console.log(request.param('not-found'), defaultValue) // 'defaultValue' + console.log(request.param('id', defaultValue)) // '1' + console.log(request.param('not-found', defaultValue)) // 'defaultValue' - console.log(request.query('world'), defaultValue) // 'hello' - console.log(request.query('not-found'), defaultValue) // 'defaultValue' + console.log(request.query('world', defaultValue)) // 'hello' + console.log(request.query('not-found', defaultValue)) // 'defaultValue' - console.log(request.header('content-type'), defaultValue) // 'application/json' - console.log(request.header('not-found'), defaultValue) // 'defaultValue' + console.log(request.header('content-type', defaultValue)) // 'application/json' + console.log(request.header('not-found', defaultValue)) // 'defaultValue' /*....*/ }) @@ -400,8 +400,6 @@ Route.get('/welcome', ({ response }) => { }) ``` - - ### The data object Use the `data` object to define properties that will be available