add missing metrics

This commit is contained in:
boufni95 2024-02-23 21:46:39 +01:00
parent 9f3e2473e3
commit 368f9aee4f
6 changed files with 3746 additions and 3686 deletions

View file

@ -110,9 +110,9 @@ The nostr server will send back a message response, and inside the body there wi
- __User__: - __User__:
- expected context content - expected context content
- __user_id__: _string_
- __app_id__: _string_ - __app_id__: _string_
- __app_user_id__: _string_ - __app_user_id__: _string_
- __user_id__: _string_
- __Admin__: - __Admin__:
- expected context content - expected context content
@ -444,120 +444,31 @@ The nostr server will send back a message response, and inside the body there wi
## Messages ## Messages
### The content of requests and response from the methods ### The content of requests and response from the methods
### AddAppInvoiceRequest ### AppUser
- __payer_identifier__: _string_ - __identifier__: _string_
- __http_callback_url__: _string_ - __info__: _[UserInfo](#UserInfo)_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_ - __max_withdrawable__: _number_
### NewInvoiceResponse ### SendAppUserToAppUserPaymentRequest
- __invoice__: _string_
### LnurlPayInfoResponse
- __tag__: _string_
- __callback__: _string_
- __maxSendable__: _number_
- __minSendable__: _number_
- __metadata__: _string_
- __allowsNostr__: _boolean_
- __nostrPubkey__: _string_
### DecodeInvoiceResponse
- __amount__: _number_
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### AddProductRequest
- __name__: _string_
- __price_sats__: _number_
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### UsersInfo
- __total__: _number_
- __no_balance__: _number_
- __negative_balance__: _number_
- __always_been_inactive__: _number_
- __balance_avg__: _number_
- __balance_median__: _number_
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
### SetMockAppBalanceRequest
- __amount__: _number_
### PayAddressResponse
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### AppMetrics
- __app__: _[Application](#Application)_
- __users__: _[UsersInfo](#UsersInfo)_
- __total_received__: _number_
- __total_spent__: _number_
- __total_available__: _number_
- __unpaid_invoices__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### ChannelBalanceEvent
- __block_height__: _number_
- __channel_id__: _string_
- __local_balance_sats__: _number_
- __remote_balance_sats__: _number_
### OpenChannel
- __channel_id__: _string_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
- __local_balance__: _number_
- __remote_balance__: _number_
### LndNodeMetrics
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
- __routing_events__: ARRAY of: _[RoutingEvent](#RoutingEvent)_
- __offline_channels__: _number_
- __online_channels__: _number_
- __pending_channels__: _number_
- __closing_channels__: _number_
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
### LndMetrics
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
### NewAddressResponse
- __address__: _string_
### LndGetInfoRequest
- __nodeId__: _number_
### SetMockAppUserBalanceRequest
- __user_identifier__: _string_
- __amount__: _number_
### MigrationUpdate
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### EncryptionExchangeRequest
- __publicKey__: _string_
- __deviceId__: _string_
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_ - __from_user_identifier__: _string_
- __to_user_identifier__: _string_
- __amount__: _number_ - __amount__: _number_
### NewAddressRequest ### NewAddressRequest
- __addressType__: _[AddressType](#AddressType)_ - __addressType__: _[AddressType](#AddressType)_
### LndMetrics
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
### PayAddressRequest
- __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### LnurlLinkResponse
- __lnurl__: _string_
- __k1__: _string_
### GetUserOperationsRequest ### GetUserOperationsRequest
- __latestIncomingInvoice__: _number_ - __latestIncomingInvoice__: _number_
- __latestOutgoingInvoice__: _number_ - __latestOutgoingInvoice__: _number_
@ -567,101 +478,51 @@ The nostr server will send back a message response, and inside the body there wi
- __latestOutgoingUserToUserPayment__: _number_ - __latestOutgoingUserToUserPayment__: _number_
- __max_size__: _number_ - __max_size__: _number_
### UserOperation ### UserOperations
- __paidAtUnix__: _number_ - __fromIndex__: _number_
- __type__: _[UserOperationType](#UserOperationType)_ - __toIndex__: _number_
- __inbound__: _boolean_ - __operations__: ARRAY of: _[UserOperation](#UserOperation)_
- __amount__: _number_
- __identifier__: _string_
- __operationId__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
- __confirmed__: _boolean_
- __tx_hash__: _string_
- __internal__: _boolean_
### UserInfo ### AddProductRequest
- __userId__: _string_ - __name__: _string_
- __balance__: _number_ - __price_sats__: _number_
- __max_withdrawable__: _number_
### PayAppUserInvoiceRequest
- __user_identifier__: _string_ - __user_identifier__: _string_
### UsageMetric
- __processed_at_ms__: _number_
- __parsed_in_nano__: _number_
- __auth_in_nano__: _number_
- __validate_in_nano__: _number_
- __handle_in_nano__: _number_
- __rpc_name__: _string_
- __batch__: _boolean_
- __nostr__: _boolean_
- __batch_size__: _number_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### AuthApp
- __app__: _[Application](#Application)_
- __auth_token__: _string_
### PayAddressRequest
- __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### PayInvoiceResponse
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### LndGetInfoResponse
- __alias__: _string_
### PayInvoiceRequest
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_ - __amount__: _number_
### ClosureMigration ### SetMockInvoiceAsPaidRequest
- __closes_at_unix__: _number_ - __invoice__: _string_
- __amount__: _number_
### RelaysMigration ### Application
- __relays__: ARRAY of: _string_ - __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### OpenChannel
- __channel_id__: _string_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
- __local_balance__: _number_
- __remote_balance__: _number_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### LndMetricsRequest ### LndMetricsRequest
- __from_unix__: _number_ *this field is optional - __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional - __to_unix__: _number_ *this field is optional
### GetUserOperationsResponse ### AddAppUserRequest
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
### LiveUserOperation
- __operation__: _[UserOperation](#UserOperation)_
### AppsMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
- __include_operations__: _boolean_ *this field is optional
### ChainBalanceEvent
- __block_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### AppUser
- __identifier__: _string_ - __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_ - __fail_if_exists__: _boolean_
- __max_withdrawable__: _number_ - __balance__: _number_
### PayAppUserInvoiceRequest ### PayInvoiceRequest
- __user_identifier__: _string_
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_ - __amount__: _number_
@ -671,53 +532,18 @@ The nostr server will send back a message response, and inside the body there wi
- __pushAmount__: _number_ - __pushAmount__: _number_
- __closeAddress__: _string_ - __closeAddress__: _string_
### AuthAppRequest ### UsersInfo
- __name__: _string_ - __total__: _number_
- __allow_user_creation__: _boolean_ *this field is optional - __no_balance__: _number_
- __negative_balance__: _number_
### LnurlLinkResponse - __always_been_inactive__: _number_
- __lnurl__: _string_ - __balance_avg__: _number_
- __k1__: _string_ - __balance_median__: _number_
### Empty
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### Application
- __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### NewInvoiceRequest ### NewInvoiceRequest
- __amountSats__: _number_ - __amountSats__: _number_
- __memo__: _string_ - __memo__: _string_
### ClosedChannel
- __channel_id__: _string_
- __capacity__: _number_
- __closed_height__: _number_
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### GetAppUserRequest
- __user_identifier__: _string_
### UserOperations
- __fromIndex__: _number_
- __toIndex__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### Product
- __id__: _string_
- __name__: _string_
- __price_sats__: _number_
### RoutingEvent ### RoutingEvent
- __incoming_channel_id__: _number_ - __incoming_channel_id__: _number_
- __incoming_htlc_id__: _number_ - __incoming_htlc_id__: _number_
@ -732,30 +558,117 @@ The nostr server will send back a message response, and inside the body there wi
- __offchain__: _boolean_ - __offchain__: _boolean_
- __forward_fail_event__: _boolean_ - __forward_fail_event__: _boolean_
### AddAppUserInvoiceRequest ### AddAppInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_ - __payer_identifier__: _string_
- __http_callback_url__: _string_ - __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_ - __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### SendAppUserToAppUserPaymentRequest ### GetAppUserRequest
- __from_user_identifier__: _string_ - __user_identifier__: _string_
- __to_user_identifier__: _string_
### UserOperation
- __paidAtUnix__: _number_
- __type__: _[UserOperationType](#UserOperationType)_
- __inbound__: _boolean_
- __amount__: _number_ - __amount__: _number_
- __identifier__: _string_
- __operationId__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
- __confirmed__: _boolean_
- __tx_hash__: _string_
- __internal__: _boolean_
### GetProductBuyLinkResponse ### LndNodeMetrics
- __link__: _string_ - __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
- __routing_events__: ARRAY of: _[RoutingEvent](#RoutingEvent)_
- __offline_channels__: _number_
- __online_channels__: _number_
- __pending_channels__: _number_
- __closing_channels__: _number_
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
### DecodeInvoiceRequest ### HandleLnurlPayResponse
- __invoice__: _string_ - __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### OpenChannelResponse ### UsageMetric
- __channelId__: _string_ - __processed_at_ms__: _number_
- __parsed_in_nano__: _number_
- __auth_in_nano__: _number_
- __validate_in_nano__: _number_
- __handle_in_nano__: _number_
- __rpc_name__: _string_
- __batch__: _boolean_
- __nostr__: _boolean_
- __batch_size__: _number_
### PayInvoiceResponse
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### RelaysMigration
- __relays__: ARRAY of: _string_
### Empty
### ChannelBalanceEvent
- __block_height__: _number_
- __channel_id__: _string_
- __local_balance_sats__: _number_
- __remote_balance_sats__: _number_
### AppMetrics
- __app__: _[Application](#Application)_
- __users__: _[UsersInfo](#UsersInfo)_
- __received__: _number_
- __spent__: _number_
- __available__: _number_
- __fees__: _number_
- __invoices__: _number_
- __total_fees__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### GetAppUserLNURLInfoRequest ### GetAppUserLNURLInfoRequest
- __user_identifier__: _string_ - __user_identifier__: _string_
- __base_url_override__: _string_ - __base_url_override__: _string_
### DecodeInvoiceRequest
- __invoice__: _string_
### ClosureMigration
- __closes_at_unix__: _number_
### LndGetInfoRequest
- __nodeId__: _number_
### ChainBalanceEvent
- __block_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### AuthApp
- __app__: _[Application](#Application)_
- __auth_token__: _string_
### EncryptionExchangeRequest
- __publicKey__: _string_
- __deviceId__: _string_
### AuthAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_
### LnurlWithdrawInfoResponse ### LnurlWithdrawInfoResponse
- __tag__: _string_ - __tag__: _string_
- __callback__: _string_ - __callback__: _string_
@ -765,6 +678,95 @@ The nostr server will send back a message response, and inside the body there wi
- __maxWithdrawable__: _number_ - __maxWithdrawable__: _number_
- __balanceCheck__: _string_ - __balanceCheck__: _string_
- __payLink__: _string_ - __payLink__: _string_
### Product
- __id__: _string_
- __name__: _string_
- __price_sats__: _number_
### LndGetInfoResponse
- __alias__: _string_
### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### SetMockAppBalanceRequest
- __amount__: _number_
### GetUserOperationsResponse
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### PayAddressResponse
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### OpenChannelResponse
- __channelId__: _string_
### NewAddressResponse
- __address__: _string_
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### SetMockAppUserBalanceRequest
- __user_identifier__: _string_
- __amount__: _number_
### DecodeInvoiceResponse
- __amount__: _number_
### LnurlPayInfoResponse
- __tag__: _string_
- __callback__: _string_
- __maxSendable__: _number_
- __minSendable__: _number_
- __metadata__: _string_
- __allowsNostr__: _boolean_
- __nostrPubkey__: _string_
### UserInfo
- __userId__: _string_
- __balance__: _number_
- __max_withdrawable__: _number_
- __user_identifier__: _string_
### GetProductBuyLinkResponse
- __link__: _string_
### LiveUserOperation
- __operation__: _[UserOperation](#UserOperation)_
### AppsMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
- __include_operations__: _boolean_ *this field is optional
### NewInvoiceResponse
- __invoice__: _string_
### MigrationUpdate
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### ClosedChannel
- __channel_id__: _string_
- __capacity__: _number_
- __closed_height__: _number_
## Enums ## Enums
### The enumerators used in the messages ### The enumerators used in the messages

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -50,11 +50,13 @@ message AppMetrics {
UsersInfo users = 2; UsersInfo users = 2;
int64 total_received = 5; int64 received = 5;
int64 total_spent = 6; int64 spent = 6;
int64 total_available = 7; int64 available = 7;
int64 fees = 8;
int64 invoices = 9;
int64 unpaid_invoices = 10; int64 total_fees = 10;
repeated UserOperation operations = 100; repeated UserOperation operations = 100;
} }

View file

@ -95,14 +95,17 @@ export default class Handler {
} }
async GetAppMetrics(req: Types.AppsMetricsRequest, app: Application | null): Promise<Types.AppMetrics> { async GetAppMetrics(req: Types.AppsMetricsRequest, app: Application | null): Promise<Types.AppMetrics> {
const totalFees = await this.storage.paymentStorage.GetTotalFeesPaidInApp(app)
const { receivingInvoices, receivingTransactions, outgoingInvoices, outgoingTransactions, receivingAddresses, userToUser } = await this.storage.paymentStorage.GetAppOperations(app, { from: req.from_unix, to: req.to_unix }) const { receivingInvoices, receivingTransactions, outgoingInvoices, outgoingTransactions, receivingAddresses, userToUser } = await this.storage.paymentStorage.GetAppOperations(app, { from: req.from_unix, to: req.to_unix })
let totalReceived = 0 let totalReceived = 0
let totalSpent = 0 let totalSpent = 0
let unpaidInvoices = 0 let unpaidInvoices = 0
let feesInRange = 0
const operations: Types.UserOperation[] = [] const operations: Types.UserOperation[] = []
receivingInvoices.forEach(i => { receivingInvoices.forEach(i => {
if (i.paid_at_unix > 0) { if (i.paid_at_unix > 0) {
totalReceived += i.paid_amount totalReceived += i.paid_amount
feesInRange += i.service_fee
if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_INVOICE, amount: i.paid_amount, inbound: true, paidAtUnix: i.paid_at_unix, confirmed: true, service_fee: i.service_fee, network_fee: 0, identifier: "", operationId: "", tx_hash: "", internal: i.internal }) if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_INVOICE, amount: i.paid_amount, inbound: true, paidAtUnix: i.paid_at_unix, confirmed: true, service_fee: i.service_fee, network_fee: 0, identifier: "", operationId: "", tx_hash: "", internal: i.internal })
} else { } else {
unpaidInvoices++ unpaidInvoices++
@ -112,6 +115,7 @@ export default class Handler {
txs.forEach(tx => { txs.forEach(tx => {
if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_TX, amount: tx.paid_amount, inbound: true, paidAtUnix: tx.paid_at_unix, confirmed: tx.confs > 1, service_fee: tx.service_fee, network_fee: 0, identifier: "", operationId: "", tx_hash: tx.tx_hash, internal: tx.internal }) if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_TX, amount: tx.paid_amount, inbound: true, paidAtUnix: tx.paid_at_unix, confirmed: tx.confs > 1, service_fee: tx.service_fee, network_fee: 0, identifier: "", operationId: "", tx_hash: tx.tx_hash, internal: tx.internal })
if (tx.confs > 1) { if (tx.confs > 1) {
feesInRange += tx.service_fee
totalReceived += tx.paid_amount totalReceived += tx.paid_amount
} }
}) })
@ -119,14 +123,17 @@ export default class Handler {
outgoingInvoices.forEach(i => { outgoingInvoices.forEach(i => {
if (req.include_operations) operations.push({ type: Types.UserOperationType.OUTGOING_INVOICE, amount: i.paid_amount, inbound: false, paidAtUnix: i.paid_at_unix, confirmed: true, service_fee: i.service_fees, network_fee: i.routing_fees, identifier: "", operationId: "", tx_hash: "", internal: i.internal }) if (req.include_operations) operations.push({ type: Types.UserOperationType.OUTGOING_INVOICE, amount: i.paid_amount, inbound: false, paidAtUnix: i.paid_at_unix, confirmed: true, service_fee: i.service_fees, network_fee: i.routing_fees, identifier: "", operationId: "", tx_hash: "", internal: i.internal })
totalSpent += i.paid_amount totalSpent += i.paid_amount
feesInRange += i.service_fees
}) })
outgoingTransactions.forEach(tx => { outgoingTransactions.forEach(tx => {
if (req.include_operations) operations.push({ type: Types.UserOperationType.OUTGOING_TX, amount: tx.paid_amount, inbound: false, paidAtUnix: tx.paid_at_unix, confirmed: tx.confs > 1, service_fee: tx.service_fees, network_fee: tx.chain_fees, identifier: "", operationId: "", tx_hash: tx.tx_hash, internal: tx.internal }) if (req.include_operations) operations.push({ type: Types.UserOperationType.OUTGOING_TX, amount: tx.paid_amount, inbound: false, paidAtUnix: tx.paid_at_unix, confirmed: tx.confs > 1, service_fee: tx.service_fees, network_fee: tx.chain_fees, identifier: "", operationId: "", tx_hash: tx.tx_hash, internal: tx.internal })
totalSpent += tx.paid_amount totalSpent += tx.paid_amount
feesInRange += tx.service_fees
}) })
userToUser.forEach(op => { userToUser.forEach(op => {
if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_USER_TO_USER, amount: op.paid_amount, inbound: true, paidAtUnix: op.paid_at_unix, confirmed: true, service_fee: op.service_fees, network_fee: 0, identifier: "", operationId: "", tx_hash: "", internal: true }) if (req.include_operations) operations.push({ type: Types.UserOperationType.INCOMING_USER_TO_USER, amount: op.paid_amount, inbound: true, paidAtUnix: op.paid_at_unix, confirmed: true, service_fee: op.service_fees, network_fee: 0, identifier: "", operationId: "", tx_hash: "", internal: true })
feesInRange += op.service_fees
}) })
const users = await this.storage.applicationStorage.GetApplicationUsers(app, { from: req.from_unix, to: req.to_unix }) const users = await this.storage.applicationStorage.GetApplicationUsers(app, { from: req.from_unix, to: req.to_unix })
@ -174,11 +181,12 @@ export default class Handler {
negative_balance: totalUsersWithNegativeBalance, negative_balance: totalUsersWithNegativeBalance,
}, },
total_received: totalReceived, received: totalReceived,
total_spent: totalSpent, spent: totalSpent,
total_available: balanceSum, available: balanceSum,
fees: feesInRange,
unpaid_invoices: unpaidInvoices, total_fees: totalFees,
invoices: receivingInvoices.length,
operations operations
} }

View file

@ -272,6 +272,26 @@ export default class {
}) })
} }
async GetTotalFeesPaidInApp(app: Application | null, entityManager = this.DB) {
if (!app) {
return 0
}
const entries = await Promise.all([
entityManager.getRepository(UserReceivingInvoice).sum("service_fee", { linkedApplication: { app_id: app.app_id } }),
entityManager.getRepository(AddressReceivingTransaction).sum("service_fee", { user_address: { linkedApplication: { app_id: app.app_id } } }),
entityManager.getRepository(UserInvoicePayment).sum("service_fees", { linkedApplication: { app_id: app.app_id } }),
entityManager.getRepository(UserTransactionPayment).sum("service_fees", { linkedApplication: { app_id: app.app_id } }),
entityManager.getRepository(UserToUserPayment).sum("service_fees", { linkedApplication: { app_id: app.app_id } })
])
let total = 0
entries.forEach(e => {
if (e) {
total += e
}
})
return total
}
async GetAppOperations(application: Application | null, { from, to }: { from?: number, to?: number }, entityManager = this.DB) { async GetAppOperations(application: Application | null, { from, to }: { from?: number, to?: number }, entityManager = this.DB) {
const q = application ? { app_id: application.app_id } : IsNull() const q = application ? { app_id: application.app_id } : IsNull()
let time: { created_at?: FindOperator<Date> } = {} let time: { created_at?: FindOperator<Date> } = {}
@ -290,7 +310,7 @@ export default class {
entityManager.getRepository(UserTransactionPayment).find({ where: { linkedApplication: q, ...time } }), entityManager.getRepository(UserTransactionPayment).find({ where: { linkedApplication: q, ...time } }),
entityManager.getRepository(UserToUserPayment).find({ where: { linkedApplication: q, ...time } }) entityManager.getRepository(UserToUserPayment).find({ where: { linkedApplication: q, ...time } })
]) ])
const receivingTransactions = await Promise.all(receivingAddresses.map(addr => entityManager.getRepository(AddressReceivingTransaction).find({ where: { user_address: { serial_id: addr.serial_id } } }))) const receivingTransactions = await Promise.all(receivingAddresses.map(addr => entityManager.getRepository(AddressReceivingTransaction).find({ where: { user_address: { serial_id: addr.serial_id }, ...time } })))
return { return {
receivingInvoices, receivingAddresses, receivingTransactions, receivingInvoices, receivingAddresses, receivingTransactions,
outgoingInvoices, outgoingTransactions, outgoingInvoices, outgoingTransactions,