Skip to content

Commit

Permalink
feat: a small refactoring to aggregate scattered dependencies and mod…
Browse files Browse the repository at this point in the history
…ify logic of some decorators
  • Loading branch information
ChoGathK committed Aug 30, 2022
1 parent 8eb3dcd commit da32364
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/decorator/async-inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AsyncProviderFactory, StaticStore } from '../struct';
* @publicApi
*/
export function AsyncInjectable(target: Type<AsyncProviderFactory>) {
StaticStore.set(target.name);
StaticStore.set(target.name, Symbol(target.name));
}
/**
* Use this decorator to inject the asynchronous provider into the class instantiation process.
Expand All @@ -19,6 +19,5 @@ export function AsyncInjectable(target: Type<AsyncProviderFactory>) {
* @publicApi
*/
export function AsyncInject(target: Type<AsyncProviderFactory>) {
const token = (target as any).getToken();
return Inject(token);
return Inject((target as any).getToken());
}
19 changes: 16 additions & 3 deletions src/decorator/controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@

import { AnyFilesInterceptor } from '@nestjs/platform-express';
import { applyDecorators, Post as Default, HttpCode, UseInterceptors } from '@nestjs/common';
import { applyDecorators, Post as DefaultPost, HttpCode, UseInterceptors } from '@nestjs/common';

/**
* Route handler (method) Decorator. Routes HTTP POST requests to the specified path.
*
* @see [Routing](https://docs.nestjs.com/controllers#routing)
*
* @publicApi
*/
export function Post(path: string | string[]) {
return applyDecorators(
Default(path),
DefaultPost(path),
HttpCode(200),
);
}

/**
* Route handler (method) Decorator. Routes HTTP POST FormData requests to the specified path.
*
* @see [Routing](https://docs.nestjs.com/controllers#routing)
*
* @publicApi
*/
export function PostFormData(path: string | string[]) {
return applyDecorators(
Post(path),
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ export {
};

export { AsyncProviderFactory } from './struct';

export * from './common';
9 changes: 6 additions & 3 deletions src/struct/async-provider-factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { FactoryProvider } from '../common';

import { StaticStore } from './store';

/**
* Asynchronous provider factory for creating
*
Expand All @@ -15,12 +17,13 @@ export class AsyncProviderFactory {
*/
public create: (...args: any[]) => FactoryProvider;
/**
* Gets the static token for the async provider factory class.
*
* @returns this.name
* @returns symbol
*
* @publicApi
* @publicStaticApi
*/
public static getToken() {
return this.name;
return StaticStore.get(this.name);
}
}
4 changes: 2 additions & 2 deletions src/struct/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class StaticStore {
return StaticStore.map.get(key);
}

public static set(key: string) {
StaticStore.map.set(key, Symbol(key));
public static set(key: string, token: symbol) {
StaticStore.map.set(key, token);
}
}

0 comments on commit da32364

Please sign in to comment.