import express = require ( 'express' ) ; import RequestContext from '@app/api/model/RequestContext' ; export function restController ( router , method , url ) { return function ( target ) { router [ method ] ( url , async function ( req , res , next ) { let context = req [ 'context' ] ; try { let result = await target ( context , req ) ; return res . json ( result ) ; } catch ( err ) { next ( err ) ; } } ) ; } ; } export function restGet ( router , url ) { return restController ( router , "get" , url ) ; } export function restPost ( router , url ) { return restController ( router , "post" , url ) ; } export function restPut ( router , url ) { return restController ( router , "put" , url ) ; } export function restDelete ( router , url ) { return restController ( router , "delete" , url ) ; }