@toss/nestjs-aop
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/toss/nestjs-aop"> <img src="https://toss.tech/wp-content/uploads/2022/11/tech-article-nest-js-02.png" alt="Logo" height="200"> </a>
20 lines (19 loc) • 631 B
text/typescript
export const AddMetadata = <K extends string | symbol = string, V = any>(
metadataKey: K,
metadataValue: V,
): MethodDecorator => {
const decoratorFactory = (
_: any,
__: string | symbol,
descriptor: PropertyDescriptor,
): TypedPropertyDescriptor<any> => {
if (!Reflect.hasMetadata(metadataKey, descriptor.value)) {
Reflect.defineMetadata(metadataKey, [], descriptor.value);
}
const metadataValues: V[] = Reflect.getMetadata(metadataKey, descriptor.value);
metadataValues.push(metadataValue);
return descriptor;
};
decoratorFactory.KEY = metadataKey;
return decoratorFactory;
};