import HttpStatus from '@xpring-eng/http-status' ; import { Request , Response } from 'express' ; import logger from '../utils/logger' ; param req param res export default function sendSuccess ( req , res ) { const status = Number ( res . locals ?. status ) || HttpStatus . OK ; if ( status === HttpStatus . Created ) { const [ , userPath ] = req . originalUrl . split ( '/' ) ; const locationHeader = [ '' , userPath , res . locals . payId ] . join ( '/' ) ; res . location ( locationHeader ) ; } if ( req . originalUrl !== '/status/health' ) { logger . debug ( status , ( ( ) : string => { if ( res . get ( 'PayID-API-Server-Version' ) ) { return '- Admin API:' ; } return '- Public API:' ; } ) ( ) , `${ req . method } ${ req . originalUrl }` ) ; } if ( res . locals . response ) { res . status ( status ) . json ( res . locals . response ) ; } else { res . sendStatus ( status ) ; } }