Skip to content

Commit

Permalink
Merge pull request #515 from toonvanstrijp/fix/docs
Browse files Browse the repository at this point in the history
fix: examples and usage guide
  • Loading branch information
rubiin authored Jun 27, 2023
2 parents 6a422b3 + add6ab3 commit cabdf6a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/guides/dto_validation/global-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ If you want a different output, create your own interceptor! For an example look
:::

## Example
A working example is available [here](https://github.com/toonvanstrijp/nestjs-i18n/tree/main/samples/simple).
A working example is available [here](https://github.com/toonvanstrijp/nestjs-i18n/tree/main/samples/dt-validation).
24 changes: 24 additions & 0 deletions docs/guides/type-safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,27 @@ export class ApiException extends Error {
:::caution
For now type safety is optional and need to be enabled. We're planning to make a breaking change where type safety is enabled by default.
:::

# Type safety with DTOS

You can also use the generated types in your DTOs. This way you can reduce the chance of having a typo in your validation messages.

```typescript title="src/craete-user.dto.ts"
import { I18nTranslations } from './generated/i18n.generated.ts';
import {
IsEmail,
IsNotEmpty,
} from 'class-validator';
import { i18nValidationMessage } from 'nestjs-i18n';

export class CreateUserDto {
@IsNotEmpty({ message: i18nValidationMessage<I18nTranslations>("validation.isNotEmpty")})
@IsEmail({}, { message: i18nValidationMessage<I18nTranslations>("validation.isEmail")})
email: string;

@IsNotEmpty({ message: i18nValidationMessage<I18nTranslations>("validation.isNotEmpty")})
password: string;

}

```
4 changes: 3 additions & 1 deletion docs/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ import { Module } from '@nestjs/common';
import * as path from 'path';
import {
AcceptLanguageResolver,
QueryResolver,
HeaderResolver,
CookieResolver,
I18nJsonLoader,
I18nModule,
QueryResolver,
} from 'nestjs-i18n';

@Module({
Expand Down

0 comments on commit cabdf6a

Please sign in to comment.