Skip to content

Commit

Permalink
clean up readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Helveg committed Dec 8, 2024
1 parent b17e806 commit 0319991
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,36 @@ type transformer you can use the type injector's class body to scaffold your dep
Its `inject` function is called with the same arguments as the `Type` function would have been.

The following example illustrates how you could return different DTO types (and thereby different
validation schemes when used in combination with `class-validator`) based on a supposed client's
validation schemes when used with `class-validator`), based on a supposed client's
configuration:

```ts
@Injectable()
class ClientDtoInjector implements TypeInjector {
constructor(
private readonly service: ClientConfigurationService
) {}
) {
}

inject(type?: TypeHelpOptions) {
const client = type.object['client'] ?? 'default';
const clientConfig = this.service.getClientConfiguration(client);
const dto = clientConfig.getNestedDTO(type.newObject, type.property);
return dto
return dto;
}
}

class OpenAccountDTO {
@IsString()
client: string;

@ValidateNested()
@InjectType(ClientDtoInjector)
accountInfo: AccountInfoDTO
accountInfo: AccountInfoDTO;
}
```

## 📜 License

`nestjs-inject-transformer` is [MIT licensed](LICENSE).

0 comments on commit 0319991

Please sign in to comment.