Abstract out DataContainer into interface

orm-types
Garrett Mills 3 years ago
parent 574ddbe9cb
commit 26d54033af
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -39,11 +39,18 @@ export interface HTTPSourceAddress {
port: number;
}
/**
* Interface describing a container that holds user input data.
*/
export interface DataContainer {
input(key?: string): any
}
/**
* A class that represents an HTTP request from a client.
*/
@Injectable()
export class Request extends ScopedContainer {
export class Request extends ScopedContainer implements DataContainer {
/** The cookie manager for the request. */
public readonly cookies: HTTPCookieJar;
@ -170,7 +177,15 @@ export class Request extends ScopedContainer {
* Get the value of an input field on the request. Spans multiple input sources.
* @param key
*/
public input(key: string) {
public input(key?: string) {
if ( !key ) {
return {
...this.parsedInput,
...this.query,
...this.uploadedFiles,
}
}
if ( key in this.parsedInput ) {
return this.parsedInput[key]
}

Loading…
Cancel
Save