This repository has been archived on 2020-08-13. You can view files and clone it, but cannot push or open issues or pull requests.
requestor/lib/classes/Transaction.ts

34 lines
778 B
TypeScript
Raw Normal View History

2020-04-09 10:31:15 +02:00
import { Request, Response } from 'express';
2020-04-09 12:29:30 +02:00
import { http } from '@scode/consts';
2020-04-09 09:14:54 +02:00
import Session from './Session';
2020-04-03 15:00:49 +02:00
2020-04-03 18:50:08 +02:00
export default class Transaction {
2020-04-03 15:00:49 +02:00
/* private */
private _req: Request;
private _res: Response;
2020-04-08 15:54:31 +02:00
/* public */
2020-04-09 12:29:30 +02:00
public status = -1;
public session?: Session;
2020-04-08 11:57:30 +02:00
public get req (): Request { return this._req; }
public get res (): Response { return this._res; }
2020-04-09 12:29:30 +02:00
public get has_status (): boolean {
return Object.values (http.status_codes)
.includes (this.status);
}
2020-04-03 15:00:49 +02:00
/* constructor */
2020-04-08 11:57:30 +02:00
public constructor (req: Request, res: Response) {
2020-04-03 15:00:49 +02:00
this._req = req;
this._res = res;
}
/* methods */
2020-04-09 11:11:19 +02:00
public finalize (data?: any): void {
2020-04-09 12:29:30 +02:00
if (this.has_status)
this._res.status (this.status);
2020-04-08 11:57:30 +02:00
this._res.end (data);
2020-04-03 15:00:49 +02:00
}
}