34 lines
778 B
TypeScript
34 lines
778 B
TypeScript
import { Request, Response } from 'express';
|
|
import { http } from '@scode/consts';
|
|
import Session from './Session';
|
|
|
|
export default class Transaction {
|
|
/* private */
|
|
private _req: Request;
|
|
private _res: Response;
|
|
|
|
/* public */
|
|
public status = -1;
|
|
public session?: Session;
|
|
|
|
public get req (): Request { return this._req; }
|
|
public get res (): Response { return this._res; }
|
|
public get has_status (): boolean {
|
|
return Object.values (http.status_codes)
|
|
.includes (this.status);
|
|
}
|
|
|
|
/* constructor */
|
|
public constructor (req: Request, res: Response) {
|
|
this._req = req;
|
|
this._res = res;
|
|
}
|
|
|
|
/* methods */
|
|
public finalize (data?: any): void {
|
|
if (this.has_status)
|
|
this._res.status (this.status);
|
|
this._res.end (data);
|
|
}
|
|
}
|