import { injectable } from 'inversify' ; import { URL } from 'url' ; import { StatusCodes } from 'http-status-codes' ; import { injectHttpContext } from './decorators' ; import { HttpResponseMessage } from './httpResponseMessage' ; import { CreatedNegotiatedContentResult , ConflictResult , OkNegotiatedContentResult , OkResult , BadRequestErrorMessageResult , BadRequestResult , ExceptionResult , InternalServerErrorResult , NotFoundResult , RedirectResult , ResponseMessageResult , StatusCodeResult , JsonResult , } from './results' ; import { HttpContext } from './interfaces' ; @ injectable ( ) export class BaseHttpController { @ injectHttpContext protected readonly httpContext ! : HttpContext ; protected created < T > ( location , content ) { return new CreatedNegotiatedContentResult ( location , content ) ; } protected conflict ( ) { return new ConflictResult ( ) ; } protected ok < T > ( content ) ; protected ok ( ) ; protected ok < T > ( content ? ) { return content === undefined ? new OkResult ( ) : new OkNegotiatedContentResult ( content ) ; } protected badRequest ( ) ; protected badRequest ( message ) ; protected badRequest ( message ? ) { return message === undefined ? new BadRequestResult ( ) : new BadRequestErrorMessageResult ( message ) ; } protected internalServerError ( ) ; protected internalServerError ( error ) ; protected internalServerError ( error ? ) { return error ? new ExceptionResult ( error ) : new InternalServerErrorResult ( ) ; } protected notFound ( ) { return new NotFoundResult ( ) ; } protected redirect ( uri ) { return new RedirectResult ( uri ) ; } protected responseMessage ( message ) { return new ResponseMessageResult ( message ) ; } protected statusCode ( statusCode ) { return new StatusCodeResult ( statusCode ) ; } protected json ( content , statusCode = StatusCodes . OK ) { return new JsonResult ( content , statusCode ) ; } }