mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-04-04 20:12:38 +00:00
33 lines
614 B
TypeScript
33 lines
614 B
TypeScript
import { Response, Request } from "express";
|
|
|
|
/**
|
|
* Response to a request
|
|
*
|
|
* @author Pierre HUBERT
|
|
*/
|
|
|
|
export class RequestHandler {
|
|
public constructor(private req : Request, private response : Response) {}
|
|
|
|
/**
|
|
* Output an error code
|
|
*
|
|
* @param code HTTP Status code
|
|
* @param message The message to send
|
|
*/
|
|
public error(code : number, message : string) {
|
|
this.response.status(code).send({
|
|
code: code,
|
|
message: message
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Send some data to the server
|
|
*
|
|
* @param data The data to send back to the server
|
|
*/
|
|
public send(data: any) {
|
|
this.response.send(data);
|
|
}
|
|
} |