Wednesday, 31 May 2017

How do I check the Model Name and Model ID for a Dynamic Role in a relationship-based route in LoopBack 3?

I am following the instructions on LoopBack's documentation about using defining a custom role, and in every case I've found so far except for routes that are automatically defined as part of a relationship for a model, the context.modelName and context.modelId are populated. In this case, I have 3 models: app, district, and app_district; app has many district, and district has many apps.

I am creating a dynamic role that should allow users to only see apps and app_districts that they have access to. When I navigate to /app/{id}, this dynamic role resolver finds the modelName and modelId of app fine, however when i navigate to /app/{id}/district/{fk} I do not get a modelName; instead, I get undefined. The same goes for the modelId

Is there a way to get the model name of district in this case?

Code snippet to show how I'm doing this:

Role.registerResolver("RegionAdminAccessingThroughDistrict", async function( role, context ) { const modelName = context.modelName; // always undefined in the above stated route if (!modelName || !context.modelId) { return true; }



via Phil Barresi

No comments:

Post a Comment