Class: TransactionContext

x2node-ws-resources~ TransactionContext

Resource handler transaction context.

new TransactionContext(call, dboFactory)

Note: The constructor is not accessible from the client code. Instances are created internally in the framework and are provided to handler extensions.
Parameters:
Name Type Description
call module:x2node-ws~ServiceCall The call.
dboFactory module:x2node-dbos~DBOFactory The DBO factory.

Members


<readonly> call :module:x2node-ws~ServiceCall

The web service endpoint call.
Type:

<readonly> dboFactory :module:x2node-dbos~DBOFactory

DBO factory.
Type:

<readonly> recordTypes :module:x2node-records~RecordTypesLibrary

Record types library.
Type:

<readonly> transaction :module:x2node-dbos~Transaction

The transaction, if active.
Type:

Methods


delete(recordTypeName, filterSpec)

Convenience shortcut for building and executing a delete DBO.
Parameters:
Name Type Description
recordTypeName string Name of the record type to delete.
filterSpec Array.<Array> Selector for records to delete.
See:
Returns:
The operation result object promise.
Type
Promise.<module:x2node-dbos~DeleteDBO~Result>

fetch(recordTypeName, querySpec)

Convenience shortcut for building and executing a fetch DBO.
Parameters:
Name Type Description
recordTypeName string Name of the record type to fetch.
querySpec Object Query specification.
See:
Returns:
The fetch result promise.
Type
Promise.<module:x2node-dbos~FetchDBO~Result>

insert(recordTypeName, records [, passThrough])

Convenience shortcut for building and executing an insert DBO.
Parameters:
Name Type Argument Description
recordTypeName string Name of the record type to insert.
records Object | Array.<Object> Record template or an array of record templates.
passThrough * <optional>
If provided, the returned promise resolves with this value instead of the inserted record ids (which are lost in that case).
See:
Returns:
Promise of the new record id(s) or the pass through object.
Type
Promise.<(string|number|Array.<(string|number)>|*)>

makeComplete()

Mark the transaction as complete. The rest of the transaction phases are skipped, the transaction is committed and the handler returns the result of the current transaction phase.

refToId(recordTypeName, ref)

Convert record reference to record id. Shortcut for recordTypes.refToId(recordTypeName, ref).
Parameters:
Name Type Description
recordTypeName string Reference target record type name.
ref string Record reference.
Throws:
If reference is invalid.
Type
module:x2node-common.X2SyntaxError
Returns:
Record id.
Type
string | number

rejectIfExists(recordTypeName, filterSpec, httpStatusCode, errorMessage)

Convenience shortcut for checking if records of a given record type matching the specified filter exist and if so, return a promise rejected with an error HTTP response.
Parameters:
Name Type Description
recordTypeName string Name of the record type to check.
filterSpec Array.<Array> Records filter.
httpStatusCode number HTTP response status code for the error response.
errorMessage string Message for the error response.
Returns:
Promise that gets rejected with a service response if matching records exist. If matching records do not exist, the promise is fulfulled with nothing.
Type
Promise.<module:x2node-ws~ServiceResponse>

rejectIfNotExactNum(recordTypeName, filterSpec, expectedNum, httpStatusCode, errorMessage)

Convenience shortcut for checking if exact number of records of a given record type matching the specified filter exists and if not, return a promise rejected with an error HTTP response. The existing records are also locked by the method in shared mode for the transaction.
Parameters:
Name Type Description
recordTypeName string Name of the record type to check.
filterSpec Array.<Array> Records filter.
expectedNum number Expected number of existing records.
httpStatusCode number HTTP response status code for the error response.
errorMessage string Message for the error response.
Returns:
Promise that gets rejected with a service response if number of existing matching records does not match. If it matches, the promise is fulfulled with nothing.
Type
Promise.<module:x2node-ws~ServiceResponse>

rejectIfNotExists(recordTypeName, filterSpec, httpStatusCode, errorMessage)

Convenience shortcut for checking if records of a given record type matching the specified filter do not exist and if so, return a promise rejected with an error HTTP response. If records do exist, they are also locked by the method in shared mode for the transaction.
Parameters:
Name Type Description
recordTypeName string Name of the record type to check.
filterSpec Array.<Array> Records filter.
httpStatusCode number HTTP response status code for the error response.
errorMessage string Message for the error response.
Returns:
Promise that gets rejected with a service response if no matching records exist. If matching records do exist, the promise is fulfulled with nothing.
Type
Promise.<module:x2node-ws~ServiceResponse>

update(recordTypeName, patch, filterSpec [, passThrough])

Convenience shortcut for building and executing an update DBO.
Parameters:
Name Type Argument Description
recordTypeName string Name of the record type to update.
patch Array.<Object> Update specification in JSON Patch format.
filterSpec Array.<Array> Selector for records to update.
passThrough * <optional>
If provided, the returned promise resolves with this value instead of the update DBO result (which is lost in that case).
See:
Returns:
Promise of either the update result object or the pass through object.
Type
Promise.<module:x2node-dbos~UpdateDBO~Result> | *