adminjs-nestjs
adminjs-nestjs copied to clipboard
extend request or context to resolve nestjs providers
currently its kinda impossible to resolve nestjs stuff inside i.e handler of actions. would be nice if this would be implemented.
my current workaround for this is to bind a moduleref on the current req obj inside the admin loader:
export class AdminLoader extends AbstractLoader {
public constructor(private readonly moduleRef: ModuleRef) {
super()
}
register(
admin: AdminJS,
httpAdapter: AbstractHttpAdapter<any, any, any>,
options: AdminModuleOptions
) {
.... lot other stuff
app.use(options.adminJsOptions.rootPath, function admin(req, res, next) {
req["resolver"] = moduleRef
return router(req, res, next)
})
}
}
so on every request i can simply do:
const roleService = request.resolver.get(RoleService, {
strict: false,
})
If there is already a way implemented, would be nice to point this out in the documentation.