import * as express from "express" ; import { IResponse , ResponseErrorInternal } from "italia-ts-commons/lib/responses" ; /**
 * Convenience method that transforms a function (handler),
 * which takes an express.Request as input and returns an IResponse,
 * into an express controller.
 */ export function toExpressHandler < T , P > ( handler , object ? ) { return ( req , res ) : Promise < void | undefined > => handler . call ( object , req ) . catch ( ResponseErrorInternal ) . then ( response => { res . locals . detail = response . detail ; response . apply ( res ) ; } ) ; } /**
 * An Express handler that always respond with the same response object
 */ export function constantExpressHandler < T > ( response ) { return ( _ , res ) => { res . locals . detail = response . detail ; response . apply ( res ) ; } ; }