2021-06-03 03:36:25 +00:00
|
|
|
import {HTTPStatus} from '../../util'
|
|
|
|
import {Request} from '../lifecycle/Request'
|
2021-03-08 16:07:10 +00:00
|
|
|
|
2021-03-25 13:50:13 +00:00
|
|
|
/**
|
|
|
|
* Abstract class that defines "factory" that knows how to write a particular
|
|
|
|
* response to the response object.
|
|
|
|
*/
|
2021-03-08 16:07:10 +00:00
|
|
|
export abstract class ResponseFactory {
|
2021-03-25 13:50:13 +00:00
|
|
|
/** The status that should be set on the response. */
|
2021-03-08 16:07:10 +00:00
|
|
|
protected targetStatus: HTTPStatus = HTTPStatus.OK
|
|
|
|
|
2021-03-25 13:50:13 +00:00
|
|
|
/**
|
|
|
|
* Called to write the response data to the HTTP response object.
|
|
|
|
* @param request
|
|
|
|
*/
|
2021-03-08 16:07:10 +00:00
|
|
|
public async write(request: Request): Promise<Request> {
|
|
|
|
request.response.setStatus(this.targetStatus)
|
|
|
|
return request
|
|
|
|
}
|
|
|
|
|
2021-03-25 13:50:13 +00:00
|
|
|
/** Set the target status of this factory. */
|
2021-06-03 03:36:25 +00:00
|
|
|
public status(status: HTTPStatus): this {
|
2021-03-08 16:07:10 +00:00
|
|
|
this.targetStatus = status
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
}
|