UNPKG

@gabliam/web-core

Version:
63 lines (62 loc) 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResponseEntity = exports.HttpStatus = void 0; const tslib_1 = require("tslib"); const http_status_codes_1 = tslib_1.__importDefault(require("http-status-codes")); exports.HttpStatus = http_status_codes_1.default; class ResponseEntity { /** * A shortcut for creating a ResponseEntity with the given body and the status set to OK. * @param body */ static ok(body) { return new ResponseEntity(body, http_status_codes_1.default.OK); } /** * Create a ResponseEntity with an ACCEPTED status. */ static accepted() { return new ResponseEntity(null, http_status_codes_1.default.ACCEPTED); } /** * Create a ResponseEntity with a BAD_REQUEST status. */ static badRequest() { return new ResponseEntity(null, http_status_codes_1.default.BAD_REQUEST); } /** * Create a ResponseEntity with a NO_CONTENT status. */ static noContent() { return new ResponseEntity(null, http_status_codes_1.default.NO_CONTENT); } /** * Create a ResponseEntity with a NOT_FOUND status. */ static notFound() { return new ResponseEntity(null, http_status_codes_1.default.NOT_FOUND); } constructor(body, status = 200) { this._status = http_status_codes_1.default.OK; this._headers = {}; this._body = null; this._body = body; this._status = status; } get status() { return this._status; } get headers() { return this._headers; } get body() { return this._body; } hasHeader() { return Object.keys(this._headers).length !== 0; } addHeader(headerName, value) { this._headers[headerName] = value; } } exports.ResponseEntity = ResponseEntity;