Module: services/transactionService

Service for managing transactions in Satoshi Showdown. Handles creating, updating, retrieving, and deleting transaction records, ensuring data integrity and consistency.

Source:

Requires

Methods

(async, inner) createRefundTransactionRecord(refundData) → {Promise.<Object>}

Creates a refund transaction record.

Parameters:
Name Type Description
refundData Object

Data for the refund transaction.

Source:
Returns:

The created refund transaction record.

Type
Promise.<Object>

(async, inner) createTransactionRecord(transactionData) → {Promise.<Object>}

Creates a new transaction record in the database.

Parameters:
Name Type Description
transactionData Object

The data for the new transaction.

Properties
Name Type Description
userRef string

ID of the user associated with the transaction.

walletRef string

ID of the wallet associated with the transaction.

transactionType string

The type of the transaction (e.g., "incoming", "outgoing").

expectedAmount number

The expected amount of the transaction in satoshis.

walletAddress string

The wallet address involved in the transaction.

userAddress string

The user's address involved in the transaction.

Source:
Throws:

If an error occurs during the creation of the transaction record in the database.

Type
Error
Returns:

A promise that resolves to the created transaction object.

Type
Promise.<Object>

(async, inner) getAllTransactionRecords() → {Promise.<Array>}

Retrieves all transaction records from the database.

Source:
Returns:

An array of all transaction objects.

Type
Promise.<Array>

(async, inner) getTransactionRecordById(transactionId) → {Promise.<Object>}

Retrieves a specific transaction record by its ID.

Parameters:
Name Type Description
transactionId string

The MongoDB reference ID of the transaction to retrieve.

Source:
Throws:

Throws an error if the transaction is not found.

Type
NotFoundError
Returns:

The found transaction object.

Type
Promise.<Object>

(async, inner) updateTransactionById(transactionId, updateData) → {Promise.<Object>}

Updates an existing transaction record in the database by its MongoDB reference ID. This function retrieves the existing transaction record, compares it with the provided update data, and applies updates only for fields that have changed. This optimizes database operations and maintains data integrity. If there are no changes, the update is skipped.

Parameters:
Name Type Description
transactionId string

The MongoDB reference ID of the transaction to update.

updateData Object

An object containing the new data for the transaction.

Source:
Throws:
  • Thrown if the transaction with the specified ID is not found in the database.

    Type
    NotFoundError
  • Thrown if there is an error during the update process.

    Type
    Error
Returns:

A promise that resolves to the updated transaction object.

Type
Promise.<Object>