import assert = require ( 'assert' ) ; import is = require ( 'is' ) ; import { CONTROLLER_FUNC_NAME , CONTROLLER_PATH } from './constants' ; internal function handleMethodDecorator ( method , path , proto , propertyKey ) { assert ( is . string ( path ) , `[Decorator @${ method }] parameter must be a string` ) ; const target = proto . constructor ; const funcs = Reflect . getMetadata ( CONTROLLER_FUNC_NAME , target ) || [ ] ; funcs . push ( propertyKey ) ; Reflect . defineMetadata ( CONTROLLER_FUNC_NAME , funcs , target ) ; let routerMetas = Reflect . getMetadata ( CONTROLLER_PATH , target , propertyKey ) || [ ] ; routerMetas . push ( { method , path } ) ; Reflect . defineMetadata ( CONTROLLER_PATH , routerMetas , target , propertyKey ) ; } decorator param path export function post ( path ) { return ( proto , propertyKey ) => { handleMethodDecorator ( 'post' , path , proto , propertyKey ) ; } ; } export function get ( path ) { return ( proto , propertyKey ) => { handleMethodDecorator ( 'get' , path , proto , propertyKey ) ; } ; } export function del ( path ) { return ( proto , propertyKey ) => { handleMethodDecorator ( 'delete' , path , proto , propertyKey ) ; } ; } export function put ( path ) { return ( proto , propertyKey ) => { handleMethodDecorator ( 'put' , path , proto , propertyKey ) ; } ; } export function patch ( path ) { return ( proto , propertyKey ) => { handleMethodDecorator ( 'patch' , path , proto , propertyKey ) ; } ; } export function options ( path ) { return ( proto , propertyKey ) => { handleMethodDecorator ( 'options' , path , proto , propertyKey ) ; } ; } export function head ( path ) { return ( proto , propertyKey ) => { handleMethodDecorator ( 'head' , path , proto , propertyKey ) ; } ; } export function all ( path ) { return ( proto , propertyKey ) => { handleMethodDecorator ( 'all' , path , proto , propertyKey ) ; } ; }