Skip to content

Commit

Permalink
refactor(common): ♻️ PR #13000 comments
Browse files Browse the repository at this point in the history
  • Loading branch information
doronguttman committed Jan 31, 2024
1 parent 385d21b commit 33aae84
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/core/helpers/router-method-factory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { HttpServer } from '@nestjs/common';
import { RequestMethod } from '@nestjs/common/enums/request-method.enum';

/**
* Ensures (via satisfies) there's a mapping between the RequestMethod enum and the HttpServer interface.
* @note This is a compile-time check, so if the interface changes, the compiler will complain.
* This is to resolve a case where a new RequestMethod is added, but the RouterMethodFactory is not updated.
*/
const RequestMethodMap = {
const REQUEST_METHOD_MAP = {
[RequestMethod.GET]: 'get',
[RequestMethod.POST]: 'post',
[RequestMethod.PUT]: 'put',
Expand All @@ -20,10 +15,9 @@ const RequestMethodMap = {

export class RouterMethodFactory {
public get(target: HttpServer, requestMethod: RequestMethod): Function {
const methodName = RequestMethodMap[requestMethod];
const methodName = REQUEST_METHOD_MAP[requestMethod];
const method = target[methodName];
if (!method) {
// There should probably be a warning message in this case
return target.use;
}
return method;
Expand Down

0 comments on commit 33aae84

Please sign in to comment.