Req
A wrapper for the request object with helper methods and access to Autonym model data.
Constructor Summary
Public Constructor | ||
public |
constructor(raw: http.IncomingMessage, model: Model, meta: Meta) |
Method Summary
Public Methods | ||
public |
async getCompleteData(): Promise<Record, AutonymError> Gets the result of merging the original data (see |
|
public |
Gets the request payload. |
|
public |
Gets the given header. |
|
public |
Gets the requested record id. |
|
public |
Gets the model instance. |
|
public |
async getOriginalData(): Promise<Record, AutonymError> For update queries, gets the data of the original record to update. |
|
public |
Gets the request query. |
|
public |
getRaw(): http.IncomingMessage Gets the raw request. |
|
public |
Gets the data that was originally on the request body. |
|
public |
Whether this request has a body. |
|
public |
Whether this is a request for a particular record. |
|
public |
Whether this is a create request. |
|
public |
Whether this is a find request. |
|
public |
Whether this is a findOne request. |
|
public |
Whether this is a findOneAndDelete request. |
|
public |
Whether this is a findOneAndUpdate request. |
|
public |
Whether this is a readonly request to fetch data. |
|
public |
Whether this is a request that will return response data. |
|
public |
Whether this step is occurring with safe data, i.e. |
|
public |
Whether this is a request that will modify the data store. |
|
public |
Merges the request data with the given data, without modifying the original request. |
Public Constructors
Public Methods
public async getCompleteData(): Promise<Record, AutonymError> source
Gets the result of merging the original data (see #getOriginalData
) with the request data.
Example:
console.log(req.getData()) // { title: 'Test' }
const originalData = await req.getCompleteData()
console.log(originalData) // { title: 'Test', body: 'This is my first post.' }
public getData(): Record source
Gets the request payload.
Throw:
If the request does not have a body. |
public getHeader(header: string): string | undefined source
Gets the given header.
Params:
Name | Type | Attribute | Description |
header | string | The header to find. |
public getId(): string source
Gets the requested record id.
Throw:
If it is a create or find request. |
public async getOriginalData(): Promise<Record, AutonymError> source
For update queries, gets the data of the original record to update. For create queries, gets an empty object.
Throw:
If the request is not a create or update request. |
Example:
console.log(req.getData()) // { title: 'Test' }
const originalData = await req.getOriginalData()
console.log(originalData) // { title: 'Hello World', body: 'This is my first post.' }
public getRaw(): http.IncomingMessage source
Gets the raw request.
Return:
http.IncomingMessage | The raw request. |
public getRequestData(): Record source
Gets the data that was originally on the request body.
Throw:
If the request does not have a body. |
public isValidated(): boolean source
Whether this step is occurring with safe data, i.e. the data has been validated, filtered, and populated with defaults.
public setData(data: Record, replace: boolean): void source
Merges the request data with the given data, without modifying the original request.
Return:
void |
Throw:
If the request does not have a body. |
Example:
console.log(req.getData()) // { title: 'Hello World' }
req.setData({ name: 'Test' })
console.log(req.getData()) // { name: 'Test', title: 'Hello World' }
console.log(req.getData()) // { title: 'Hello World' }
req.setData({ name: 'Test' }, true)
console.log(req.getData()) // { name: 'Test' }