@nestjs/core
Version:
The core of NestJS, a TypeScript framework for Node.js backends: modules, dependency injection and the request pipeline, on Express, Fastify or node:http.
31 lines (30 loc) • 969 B
JavaScript
import { RequestMethod } from '@nestjs/common';
export const REQUEST_METHOD_MAP = {
[RequestMethod.GET]: 'get',
[RequestMethod.POST]: 'post',
[RequestMethod.PUT]: 'put',
[RequestMethod.DELETE]: 'delete',
[RequestMethod.PATCH]: 'patch',
[RequestMethod.ALL]: 'all',
[RequestMethod.OPTIONS]: 'options',
[RequestMethod.HEAD]: 'head',
[RequestMethod.SEARCH]: 'search',
[RequestMethod.PROPFIND]: 'propfind',
[RequestMethod.PROPPATCH]: 'proppatch',
[RequestMethod.MKCOL]: 'mkcol',
[RequestMethod.COPY]: 'copy',
[RequestMethod.MOVE]: 'move',
[RequestMethod.LOCK]: 'lock',
[RequestMethod.UNLOCK]: 'unlock',
[RequestMethod.QUERY]: 'query',
};
export class RouterMethodFactory {
get(target, requestMethod) {
const methodName = REQUEST_METHOD_MAP[requestMethod];
const method = target[methodName];
if (!method) {
return target.use;
}
return method;
}
}