Skip to content

Commit 6cafe17

Browse files
Update README.md
Adds custom entities usage to doc
1 parent a72f635 commit 6cafe17

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

README.md

+67-2
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,76 @@ export class TestSecuredController {
162162
}
163163
}
164164
```
165+
You can now add the `entities` option to your app root module
166+
167+
```typescript
168+
//app.module.ts
169+
import { Module } from '@nestjs/common';
170+
import { OAuth2Module } from '@switchit/nestjs-oauth2-server';
171+
172+
@Module({
173+
imports: [
174+
OAuth2Module.forRoot({
175+
userLoader: new UserLoader(),
176+
userValidator: new UserValidator(),
177+
entities: [
178+
ClientEntity,
179+
AccessTokenEntity,
180+
],
181+
}),
182+
],
183+
})
184+
export class AppModule {}
185+
```
186+
187+
Also for async
188+
```typescript
189+
@Module({
190+
imports: [
191+
OAuth2Module.forRootAsync({
192+
useFactory: () => ({
193+
userLoader: new UserLoader(),
194+
userValidator: new UserValidator(),
195+
entities: [
196+
ClientEntity,
197+
AccessTokenEntity,
198+
],
199+
})
200+
}),
201+
],
202+
})
203+
```
204+
205+
## Using custom entities
206+
207+
**OPTIONAL**: You can also use custom `entities` either by extending from the on that comes with the module or create a new entity that conforms with the module's entities.
208+
e.g
209+
```typescript
210+
...
211+
import { ClientEntity as OClientEntity } from '@switchit/nestjs-oauth2-server/dist/domain/client.entity';
212+
213+
@Entity('...')
214+
@Unique(['client_id'])
215+
export class ClientEntity extends OClientEntity {
216+
...
217+
}
218+
```
219+
220+
```typescript
221+
...
222+
import { ClientEntity } from './client.entity'; // Use your client entity here
223+
import { AccessTokenEntity as OAccessTokenEntity } from '@switchit/nestjs-oauth2-server/dist/domain/access-token.entity';
224+
225+
@Entity('...')
226+
export class AccessTokenEntity extends OAccessTokenEntity {
227+
...
228+
}
229+
```
165230

166231
## Adding the entities to your TypeORM configuration
167232

168233
**IMPORTANT**: The module comes with entities you have to add the configuration `node_modules/@switchit/**/*.entity.js`
169-
to let typeorm scan your entities or add them to the `entitie` configuration variable in TypeORM.
234+
to let typeorm scan your entities or add them to the `entities` configuration variable in TypeORM.
170235

171236
## Using the global validation pipes
172237

@@ -184,4 +249,4 @@ async function bootstrap() {
184249
await app.listen(3000);
185250
}
186251
bootstrap();
187-
```
252+
```

0 commit comments

Comments
 (0)