structure

This commit is contained in:
Timo Hocker
2020-04-08 15:18:14 +02:00
parent 332e833134
commit f00db0efe5
4 changed files with 8 additions and 8 deletions

23
lib/classes/status.ts Normal file
View File

@ -0,0 +1,23 @@
import http from '@scode/consts';
export default class Status {
private _status = -1;
public get status (): number {
if (this._status === -1)
throw new Error ('status undefined');
return this._status;
}
public set status (value: number): void {
this._status = value;
}
public get has_status (): boolean {
return this._status !== -1;
}
public ok (): void {
this._status = http.status_ok;
}
}

View File

@ -0,0 +1,28 @@
import { Request, Response } from '@types/express/index.d.ts';
import Status from './status.ts';
export default class Transaction {
/* private */
private _req: Request;
private _res: Response;
private _status: Status;
/* properties */
public get req (): Request { return this._req; }
public get res (): Response { return this._res; }
public get status (): Status { return this._status; }
/* constructor */
public constructor (req: Request, res: Response) {
this._req = req;
this._res = res;
this._status = new Status;
}
/* methods */
public end (data): void {
if (this.status !== -1)
this._res.status (this.status);
this._res.end (data);
}
}