needle-innovision / nestjs-tenancy

Multi-tenancy approach for nestjs - currently supported only for mongodb with mongoose
MIT License
187 stars 58 forks source link

Optional tenant id checking based on request route path #30

Open ephrimlawrence opened 2 years ago

ephrimlawrence commented 2 years ago

Fix for #27

This PR adds skipTenantCheck option to TenancyModuleOptions. If skipTenantCheck is true for a request, tenant database connection will be bypassed.

As in the example below, the tenant DB connection will be bypassed for all /birds* routes.

TenancyModule.forRoot({
    tenantIdentifier: 'X-TenantId',
    options: {},
    uri: (tenantId: string) => `mongodb://localhost/tenant-${tenantId}`,
    skipTenantCheck: (req) => req.route.path.match(/^\/birds*/) != null,
})
ephrimlawrence commented 2 years ago

@sandeepsuvit any feedback on this PR? We really need the optional tenancy check feature

sandeepsuvit commented 2 years ago

Hi @ephrimlawrence the reason why i kept it on hold is because of difference of opinions on this implementation. Please refer to the following comment

Also there is another PR pending with similar functionality but using a guard implementation.

Please let me know your viewpoint on these.

Robokishan commented 1 year ago

This is very good feature.! any thing you can do this to merge ? @sandeepsuvit