mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-11 03:14:47 +00:00
29 lines
911 B
TypeScript
29 lines
911 B
TypeScript
import { type CustomDecorator } from '@nestjs/common';
|
|
|
|
// implementation copied from SetMetadata, but tweaked to get existing values
|
|
// of the metadataKey and accumulate it with the new metadataValue
|
|
export function SetMultipleMetadata(
|
|
metadataKey,
|
|
metadataValue,
|
|
): CustomDecorator {
|
|
const decoratorFactory: CustomDecorator = (target, key?, descriptor?) => {
|
|
// .start: tweak
|
|
// descriptor?.value = function decorator; target = class decorator
|
|
const accumulatedVal =
|
|
Reflect.getMetadata(metadataKey, descriptor?.value ?? target) ?? [];
|
|
accumulatedVal.push(metadataValue);
|
|
// .end: tweak
|
|
|
|
if (descriptor) {
|
|
Reflect.defineMetadata(metadataKey, accumulatedVal, descriptor.value);
|
|
return descriptor;
|
|
}
|
|
|
|
Reflect.defineMetadata(metadataKey, accumulatedVal, target);
|
|
return target;
|
|
};
|
|
|
|
decoratorFactory.KEY = metadataKey;
|
|
return decoratorFactory;
|
|
}
|