Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
gapinto committed Sep 9, 2020
1 parent 117280b commit 05619d3
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions README.md
Expand Up @@ -161,7 +161,7 @@ export class CustomTenantValidator implements TenancyValidator {
* @returns
* @memberof CustomTenantValidator
*/
setTenantId(tenantId: string): TenantValidator {
setTenantId(tenantId: string): TenancyValidator {
this._tenantId = tenantId;
return this; // Make sure to return the instance of the class back here.
}
Expand All @@ -186,7 +186,7 @@ export class CustomTenantValidator implements TenancyValidator {

Export the validator from your tenant module

**app.module.ts**
**tenant.module.ts**

```typescript
import { Module } from '@nestjs/common';
Expand Down Expand Up @@ -215,6 +215,18 @@ import { CustomTenantValidator } from './validators/custom-tenant.validator';
export class TenantModule {}
```

Export the validator from your config folder

**config.ts**

```
export default () => ({
database: {
uri: process.env.MONGO_URI
}
});
```

Finally you will also need to modify the module configuration.

**app.module.ts**
Expand Down Expand Up @@ -247,7 +259,7 @@ import { CustomTenantValidator } from './tenant/validators/custom-tenant.validat
return {
// Base tenant configurations
tenantIdentifier: 'X-TENANT-ID',
options: {},
options: () => {},
uri: (tenantId: string) => `mongodb://localhost/test-tenant-${tenantId}`,
// Custom validator to check if the tenant exist in common database
validator: (tenantId: string) => tVal.setTenantId(tenantId),
Expand Down Expand Up @@ -278,7 +290,7 @@ import { CatsModule } from "./cat.module.ts";
TenancyModule.forRoot({
// This will allow the library to extract the subdomain as tenant id
isTenantFromSubdomain: true,
options: {},
options: () => {},
uri: (tenantId: string) => `mongodb://localhost/test-tenant-${tenantId}`,
}),
CatsModule,
Expand Down

0 comments on commit 05619d3

Please sign in to comment.