Skip to content

SudoSOS Back-end API / transactions / TransactionService

Class: TransactionService ​

Extends ​

Constructors ​

Constructor ​

ts
new TransactionService(manager?): TransactionService;

Parameters ​

ParameterType
manager?EntityManager

Returns ​

TransactionService

Inherited from ​

WithManager.constructor

Properties ​

PropertyModifierTypeInherited from
managerprotectedEntityManagerWithManager.manager

Methods ​

asSubTransactionResponse() ​

ts
asSubTransactionResponse(subTransaction, cachedCost?): Promise<SubTransactionResponse>;

Creates a sub transaction response from a sub transaction

Parameters ​

ParameterTypeDescription
subTransactionSubTransaction-
cachedCost?DineroOptional pre-calculated cost to avoid recalculation

Returns ​

Promise<SubTransactionResponse>

  • the sub transaction response

asTransaction() ​

ts
asTransaction(
   req, 
   context, 
update?): Promise<Transaction>;

Creates a transaction from a transaction request

Parameters ​

ParameterTypeDescription
reqTransactionRequestthe transaction request to cast
contextTransactionContexttransaction context with loaded entities (required)
update?Transaction-

Returns ​

Promise<Transaction>

  • the transaction

asTransactionResponse() ​

ts
asTransactionResponse(
   transaction, 
   totalCost?, 
context?): Promise<TransactionResponse>;

Creates a transaction response from a transaction (using cached cost)

Parameters ​

ParameterTypeDescription
transactionTransaction-
totalCost?DineroOptional pre-calculated total cost
context?TransactionContextOptional transaction context with cached entities and costs

Returns ​

Promise<TransactionResponse>

  • the transaction response

createTransaction() ​

ts
createTransaction(req, context): Promise<Transaction>;

Saves a transaction to the database, the transaction request should be verified beforehand

Parameters ​

ParameterTypeDescription
reqTransactionRequestthe transaction request to save
contextTransactionContexttransaction context with loaded entities (required)

Returns ​

Promise<Transaction>

  • the saved transaction

deleteTransaction() ​

ts
deleteTransaction(id): Promise<Transaction>;

Deletes a transaction

Parameters ​

ParameterTypeDescription
idnumberthe id of the requested transaction

Returns ​

Promise<Transaction>

  • the deleted transaction

getRecentlyChargedUsers() ​

ts
getRecentlyChargedUsers(createdById, take?): Promise<User[]>;

Returns the distinct set of users that the given user has most recently charged via an authenticated point of sale (useAuthentication = true), ordered by the most recent transaction timestamp descending.

Parameters ​

ParameterTypeDefault valueDescription
createdByIdnumberundefinedThe user whose cashier history to query
takenumber50Maximum number of users to return

Returns ​

Promise<User[]>


getSingleTransaction() ​

ts
getSingleTransaction(id): Promise<Transaction>;

Gets a single transaction from the database by id

Parameters ​

ParameterTypeDescription
idnumberthe id of the requested transaction

Returns ​

Promise<Transaction>

  • the requested transaction transaction

getTotalCost() ​

ts
getTotalCost(rows, productMap?): Promise<Dinero>;

Gets total cost of a transaction with values stored in the database

Parameters ​

ParameterTypeDescription
rowsSubTransactionRowRequest[]-
productMap?Map<string, ProductRevision>Optional map of pre-loaded products to avoid queries

Returns ​

Promise<Dinero>

  • the total cost of a transaction

getTransactionReport() ​

ts
getTransactionReport(parameters): Promise<TransactionReport>;

Generates a transaction report object from the given transaction filter parameters

Parameters ​

ParameterTypeDescription
parametersTransactionFilterParametersParameters describing what should be included in the report

Returns ​

Promise<TransactionReport>


getTransactionReportData() ​

ts
getTransactionReportData(
   baseTransactions, 
   exclusiveToId, 
dropInvoiced?): Promise<TransactionReportData>;

Creates TransactionReportData for the given baseTransactions

Parameters ​

ParameterTypeDefault valueDescription
baseTransactionsBaseTransactionResponse[]undefinedTransactions to parse
exclusiveToIdnumberundefinedIf not undefined it will drop all Sub transactions with a toId different from the param.
dropInvoicedbooleantrueIf invoiced SubTransactionRows should be ignored, defaults to true

Returns ​

Promise<TransactionReportData>


getTransactionReportResponse() ​

ts
getTransactionReportResponse(parameters): Promise<TransactionReportResponse>;

Creates a transaction report response from the given parameters

Parameters ​

ParameterTypeDescription
parametersTransactionFilterParameters-

Returns ​

Promise<TransactionReportResponse>


getTransactions() ​

ts
getTransactions(
   params, 
   pagination?, 
user?): Promise<[BaseTransactionResponse[], number]>;

Returns all transactions requested with the filter

Parameters ​

ParameterTypeDescription
paramsTransactionFilterParametersthe filter parameters
paginationPaginationParameters-
user?UserA user that is involved in all transactions

Returns ​

Promise<[BaseTransactionResponse[], number]>

  • the transactions without sub transactions and total count

getTransactionsFromBaseTransactions() ​

ts
getTransactionsFromBaseTransactions(baseTransactions, dropInvoiced?): Promise<Transaction[]>;

Parameters ​

ParameterTypeDefault value
baseTransactionsBaseTransactionResponse[]undefined
dropInvoicedbooleantrue

Returns ​

Promise<Transaction[]>


updateTransaction() ​

ts
updateTransaction(id, req): Promise<Transaction>;

Updates a transaction and its user relations in the database

Parameters ​

ParameterTypeDescription
idnumberrequested transaction id
reqTransactionRequestnew transaction request

Returns ​

Promise<Transaction>

updated transaction


verifyBalance() ​

ts
verifyBalance(req, totalCost?): Promise<boolean>;

Verifies whether a user has a sufficient balance to complete the transaction

Parameters ​

ParameterTypeDescription
reqTransactionRequestthe transaction request to verify
totalCost?DineroOptional pre-calculated total cost to avoid recalculation

Returns ​

Promise<boolean>

  • whether user's balance is ok or not

verifyTransaction() ​

ts
verifyTransaction(req, isUpdate?): Promise<{
  context?: TransactionContext;
  valid: boolean;
}>;

Verifies whether a transaction is valid and returns context with loaded entities

Parameters ​

ParameterTypeDescription
reqTransactionRequestthe transaction request to verify
isUpdate?boolean-

Returns ​

Promise<{ context?: TransactionContext; valid: boolean; }>

  • verification result and context (context is always provided if valid)

dineroEq() ​

ts
static dineroEq(req, din): boolean;

Tests whether a dinero request equals a dinero object

Parameters ​

ParameterTypeDescription
reqDineroObjectRequestdinero request
dinDinerodinero object

Returns ​

boolean

  • equality of the parameters

invalidateBalanceCache() ​

ts
static invalidateBalanceCache(transaction): Promise<void>;

Invalidates user balance cache

Parameters ​

ParameterTypeDescription
transactionTransactiontransaction holding users to invalidate

Returns ​

Promise<void>