Savory/Danet

SetMetadata function to create decorators

Sorikairox opened this issue · 5 comments

Is your feature request related to a problem? Please describe.

If I want to set a controller/method metadata, for example with a Public decorator, I have to create it as follows:

export const IS_PUBLIC_KEY = 'isPublic';
export const Public = () =>
(
	// deno-lint-ignore ban-types
	target: ControllerConstructor | Object,
	propertyKey?: string | symbol,
	// deno-lint-ignore no-explicit-any
	descriptor?: TypedPropertyDescriptor<any>,
) => {
	if (propertyKey && descriptor) {
		MetadataHelper.setMetadata(
			IS_PUBLIC_KEY,
			true,
			descriptor.value,
		);
	} else {
		MetadataHelper.setMetadata(IS_PUBLIC_KEY, true, target);
	}
};

This is way too verbose, especially when creating multiple decorators that only set metadata.

Describe the solution you'd like

We should create a SetMetadata function to be used as follows:

export const IS_PUBLIC_KEY = 'isPublic';
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);

Can i work on this issue ?

@Niravprajapati1 sure go ahead

where do i want to add this function?

Probably somewhere near MetadataHelper

How can i make this function i am begginer so i need some help !