Skip to content

Commit

Permalink
fix: missing router options (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 authored Oct 28, 2020
1 parent d3a27cb commit b1693b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions packages/decorator/src/web/requestMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ import { attachClassMetadata, WEB_ROUTER_KEY } from '../';
import { MiddlewareParamArray } from '../interface';

export interface RouterOption {
// 路由
path?: string;
// 请求类型
requestMethod: string;
// 路由别名
routerName?: string;
method: string;
// 装饰器附加的方法
method?: string;
// 路由附加的中间件
middleware?: MiddlewareParamArray;
// 路由摘要
summary?: string;
// 路由描述
description?: string;
}

export const RequestMethod = {
Expand All @@ -25,25 +34,16 @@ export const RequestMethod = {

const defaultMetadata = {
path: '/',
method: RequestMethod.GET,
requestMethod: RequestMethod.GET,
routerName: null,
middleware: [],
};

export interface RequestMappingMetadata {
path?: string;
method: string;
routerName?: string;
middleware?: MiddlewareParamArray;
summary?: string;
description?: string;
}

export const RequestMapping = (
metadata: RequestMappingMetadata = defaultMetadata
metadata: RouterOption = defaultMetadata
): MethodDecorator => {
const path = metadata.path || '/';
const requestMethod = metadata.method || RequestMethod.GET;
const requestMethod = metadata.requestMethod || RequestMethod.GET;
const routerName = metadata.routerName;
const middleware = metadata.middleware;

Expand Down Expand Up @@ -76,7 +76,7 @@ const createMappingDecorator = (method: string) => (
} = { middleware: [] }
): MethodDecorator => {
return RequestMapping(Object.assign(routerOptions, {
method,
requestMethod: method,
path,
}));
};
Expand Down
2 changes: 1 addition & 1 deletion packages/decorator/test/web/requestMapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('/test/web/requestMapping.test.ts', () => {
});

const bb = RequestMapping({
method: null,
requestMethod: null,
});

bb(Test, 'ttt', null);
Expand Down

0 comments on commit b1693b8

Please sign in to comment.