needle-innovision / nestjs-tenancy

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

Using discriminators #31

Open esimonm opened 2 years ago

esimonm commented 2 years ago

Hi @sandeepsuvit, I hope you are doing well. First, thanks for developing this, I've found it super helpful and so easy to apply!

I wonder if it'd be possible for us to apply discriminators the same way as Nest currently does (please see the application in https://docs.nestjs.com/techniques/mongodb#discriminators). Currently, there is no way to declare the discriminators in the module's imports, as it throws a type error as the discriminators field is not declared in the ModelDefinition interface you created.

This would be a great addition to our current projects.

Again, thanks for all your effort, looking forward to your reply!

sandeepsuvit commented 2 years ago

Hi @esimonm thanks for the feedback. Regarding you query on discriminators i don't think the library does a hard type check against this. However this check can come from the underlying dependency types of mongoose that are being used is what my guess is. If you think otherwise can you point me to the line in the code where this is happening with a sample code so that i can debug it further.

esimonm commented 2 years ago

Thanks for the quick reply @sandeepsuvit, really appreciate it. Please see the following error I'm getting when declaring the discriminators on the module's TenancyModule.forFeature as shown in Nest's documentation.

image

And here is the ModelDefinition interface:

image

Let me know if you need any more info, thanks!

sandeepsuvit commented 2 years ago

Hi @esimonm thanks for pointing it out. I haven't used discriminators with nestjs before so i am not familiar with its functionality. I have made the changes referring to nestjs/mongoose wrapper implementation. The changes are available under the following branch. Please check it out and let me know if its working for you. If it does, then ill release a new version with these changes.

esimonm commented 2 years ago

Thanks for the quick update! Tried it and there are no longer any type errors, but unfortunately, it's still giving an error when compiling as shown here:

image

"Issue" is the Entity the module is based on. Two other entities are used in the discriminator array. Seems like the Tenancy module is not importing the Issue module?

Please let me know if there's any more info needed. Thanks again.

sandeepsuvit commented 2 years ago

@esimonm can you provide me a minimal example working sample repo to test this out.