SudoSOS Back-end API / transactions / TransactionService
Class: TransactionService ​
Extends ​
Constructors ​
Constructor ​
new TransactionService(manager?): TransactionService;Parameters ​
| Parameter | Type |
|---|---|
manager? | EntityManager |
Returns ​
TransactionService
Inherited from ​
Properties ​
| Property | Modifier | Type | Inherited from |
|---|---|---|---|
manager | protected | EntityManager | WithManager.manager |
Methods ​
asSubTransactionResponse() ​
asSubTransactionResponse(subTransaction, cachedCost?): Promise<SubTransactionResponse>;Creates a sub transaction response from a sub transaction
Parameters ​
| Parameter | Type | Description |
|---|---|---|
subTransaction | SubTransaction | - |
cachedCost? | Dinero | Optional pre-calculated cost to avoid recalculation |
Returns ​
Promise<SubTransactionResponse>
- the sub transaction response
asTransaction() ​
asTransaction(
req,
context,
update?): Promise<Transaction>;Creates a transaction from a transaction request
Parameters ​
| Parameter | Type | Description |
|---|---|---|
req | TransactionRequest | the transaction request to cast |
context | TransactionContext | transaction context with loaded entities (required) |
update? | Transaction | - |
Returns ​
Promise<Transaction>
- the transaction
asTransactionResponse() ​
asTransactionResponse(
transaction,
totalCost?,
context?): Promise<TransactionResponse>;Creates a transaction response from a transaction (using cached cost)
Parameters ​
| Parameter | Type | Description |
|---|---|---|
transaction | Transaction | - |
totalCost? | Dinero | Optional pre-calculated total cost |
context? | TransactionContext | Optional transaction context with cached entities and costs |
Returns ​
Promise<TransactionResponse>
- the transaction response
createTransaction() ​
createTransaction(req, context): Promise<Transaction>;Saves a transaction to the database, the transaction request should be verified beforehand
Parameters ​
| Parameter | Type | Description |
|---|---|---|
req | TransactionRequest | the transaction request to save |
context | TransactionContext | transaction context with loaded entities (required) |
Returns ​
Promise<Transaction>
- the saved transaction
deleteTransaction() ​
deleteTransaction(id): Promise<Transaction>;Deletes a transaction
Parameters ​
| Parameter | Type | Description |
|---|---|---|
id | number | the id of the requested transaction |
Returns ​
Promise<Transaction>
- the deleted transaction
getRecentlyChargedUsers() ​
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 ​
| Parameter | Type | Default value | Description |
|---|---|---|---|
createdById | number | undefined | The user whose cashier history to query |
take | number | 50 | Maximum number of users to return |
Returns ​
Promise<User[]>
getSingleTransaction() ​
getSingleTransaction(id): Promise<Transaction>;Gets a single transaction from the database by id
Parameters ​
| Parameter | Type | Description |
|---|---|---|
id | number | the id of the requested transaction |
Returns ​
Promise<Transaction>
- the requested transaction transaction
getTotalCost() ​
getTotalCost(rows, productMap?): Promise<Dinero>;Gets total cost of a transaction with values stored in the database
Parameters ​
| Parameter | Type | Description |
|---|---|---|
rows | SubTransactionRowRequest[] | - |
productMap? | Map<string, ProductRevision> | Optional map of pre-loaded products to avoid queries |
Returns ​
Promise<Dinero>
- the total cost of a transaction
getTransactionReport() ​
getTransactionReport(parameters): Promise<TransactionReport>;Generates a transaction report object from the given transaction filter parameters
Parameters ​
| Parameter | Type | Description |
|---|---|---|
parameters | TransactionFilterParameters | Parameters describing what should be included in the report |
Returns ​
Promise<TransactionReport>
getTransactionReportData() ​
getTransactionReportData(
baseTransactions,
exclusiveToId,
dropInvoiced?): Promise<TransactionReportData>;Creates TransactionReportData for the given baseTransactions
Parameters ​
| Parameter | Type | Default value | Description |
|---|---|---|---|
baseTransactions | BaseTransactionResponse[] | undefined | Transactions to parse |
exclusiveToId | number | undefined | If not undefined it will drop all Sub transactions with a toId different from the param. |
dropInvoiced | boolean | true | If invoiced SubTransactionRows should be ignored, defaults to true |
Returns ​
Promise<TransactionReportData>
getTransactionReportResponse() ​
getTransactionReportResponse(parameters): Promise<TransactionReportResponse>;Creates a transaction report response from the given parameters
Parameters ​
| Parameter | Type | Description |
|---|---|---|
parameters | TransactionFilterParameters | - |
Returns ​
Promise<TransactionReportResponse>
getTransactions() ​
getTransactions(
params,
pagination?,
user?): Promise<[BaseTransactionResponse[], number]>;Returns all transactions requested with the filter
Parameters ​
| Parameter | Type | Description |
|---|---|---|
params | TransactionFilterParameters | the filter parameters |
pagination | PaginationParameters | - |
user? | User | A user that is involved in all transactions |
Returns ​
Promise<[BaseTransactionResponse[], number]>
- the transactions without sub transactions and total count
getTransactionsFromBaseTransactions() ​
getTransactionsFromBaseTransactions(baseTransactions, dropInvoiced?): Promise<Transaction[]>;Parameters ​
| Parameter | Type | Default value |
|---|---|---|
baseTransactions | BaseTransactionResponse[] | undefined |
dropInvoiced | boolean | true |
Returns ​
Promise<Transaction[]>
updateTransaction() ​
updateTransaction(id, req): Promise<Transaction>;Updates a transaction and its user relations in the database
Parameters ​
| Parameter | Type | Description |
|---|---|---|
id | number | requested transaction id |
req | TransactionRequest | new transaction request |
Returns ​
Promise<Transaction>
updated transaction
verifyBalance() ​
verifyBalance(req, totalCost?): Promise<boolean>;Verifies whether a user has a sufficient balance to complete the transaction
Parameters ​
| Parameter | Type | Description |
|---|---|---|
req | TransactionRequest | the transaction request to verify |
totalCost? | Dinero | Optional pre-calculated total cost to avoid recalculation |
Returns ​
Promise<boolean>
- whether user's balance is ok or not
verifyTransaction() ​
verifyTransaction(req, isUpdate?): Promise<{
context?: TransactionContext;
valid: boolean;
}>;Verifies whether a transaction is valid and returns context with loaded entities
Parameters ​
| Parameter | Type | Description |
|---|---|---|
req | TransactionRequest | the transaction request to verify |
isUpdate? | boolean | - |
Returns ​
Promise<{ context?: TransactionContext; valid: boolean; }>
- verification result and context (context is always provided if valid)
dineroEq() ​
static dineroEq(req, din): boolean;Tests whether a dinero request equals a dinero object
Parameters ​
| Parameter | Type | Description |
|---|---|---|
req | DineroObjectRequest | dinero request |
din | Dinero | dinero object |
Returns ​
boolean
- equality of the parameters
invalidateBalanceCache() ​
static invalidateBalanceCache(transaction): Promise<void>;Invalidates user balance cache
Parameters ​
| Parameter | Type | Description |
|---|---|---|
transaction | Transaction | transaction holding users to invalidate |
Returns ​
Promise<void>