admin管理员组文章数量:1429430
I have to collect all decorator value that appears in different place in my app as string and then saving them to database at runtime, i don't have to add them twice (in database and in code),
i have tried to do it but i could not figure out i use
Reflector
api from nestjs as following
this.reflector.getAll<string>('access', context.getHandler())
but i could not get context.getHandler()
during run time
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
// Here is where i want to save
await app.listen(3000);
}
bootstrap();
here is my decorator
@HashPermission('access_value')
Please assist
I have to collect all decorator value that appears in different place in my app as string and then saving them to database at runtime, i don't have to add them twice (in database and in code),
i have tried to do it but i could not figure out i use
Reflector
api from nestjs as following
this.reflector.getAll<string>('access', context.getHandler())
but i could not get context.getHandler()
during run time
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
// Here is where i want to save
await app.listen(3000);
}
bootstrap();
here is my decorator
@HashPermission('access_value')
Please assist
Share Improve this question asked Jun 14, 2021 at 11:46 Izweb TechnologiesIzweb Technologies 1582 silver badges9 bronze badges1 Answer
Reset to default 7For something like this, you'll either need to make use of something like Nest's undocumented DiscoveryService
or a package like @golevelup/nestjs-discovery
which is a friendly wrapper around Nest's package. You can then make use of methods like this.discoveryService.methodsAndControllerMethodsWithMetaAtKey
to get the classes and methods that have that metadata, then you can use the reflector class on each method to get the metadata value.
本文标签: javascripthow to scan all decorators value at runtime in nestjsStack Overflow
版权声明:本文标题:javascript - how to scan all decorators value at runtime in nestjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745480192a2660140.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论