Skip to content

Commit

Permalink
Merge pull request #209 from AthennaIO/develop
Browse files Browse the repository at this point in the history
fix(ctx): adjust default value in examples
  • Loading branch information
jlenon7 authored May 8, 2024
2 parents b4b1b57 + 5dcad89 commit 5454db5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
16 changes: 15 additions & 1 deletion docs/orm/annotations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
22 changes: 7 additions & 15 deletions docs/orm/query-builder.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 10 additions & 12 deletions docs/rest-api-application/request-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/*....*/
})
Expand Down Expand Up @@ -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'

/*....*/
})
Expand Down Expand Up @@ -400,8 +400,6 @@ Route.get('/welcome', ({ response }) => {
})
```



### The data object

Use the `data` object to define properties that will be available
Expand Down

0 comments on commit 5454db5

Please sign in to comment.