garrettmills
1d5056b753
All checks were successful
continuous-integration/drone/push Build is passing
27 lines
772 B
TypeScript
27 lines
772 B
TypeScript
import {HTTPStatus} from '../../util'
|
|
import {Request} from '../lifecycle/Request'
|
|
|
|
/**
|
|
* Abstract class that defines "factory" that knows how to write a particular
|
|
* response to the response object.
|
|
*/
|
|
export abstract class ResponseFactory {
|
|
/** The status that should be set on the response. */
|
|
protected targetStatus: HTTPStatus = HTTPStatus.OK
|
|
|
|
/**
|
|
* Called to write the response data to the HTTP response object.
|
|
* @param request
|
|
*/
|
|
public async write(request: Request): Promise<Request> {
|
|
request.response.setStatus(this.targetStatus)
|
|
return request
|
|
}
|
|
|
|
/** Set the target status of this factory. */
|
|
public status(status: HTTPStatus): this {
|
|
this.targetStatus = status
|
|
return this
|
|
}
|
|
}
|