Transactions model #1

Closed
opened 2025-02-13 11:16:08 -05:00 by null · 0 comments
Owner

the transactions table will track multi-currency balance changes on users
each row in the table has the user_id sats_balance cents_balance, and metadata

a transaction has a type one of:

CREDIT - a manual increase in credit granted by admin
REWARD - an automatic increase in credit applied as a reward
REDEEM - a user-consenting or automatic decrease in credit spent on the store or subscription
REVOKE - a manual decrease in credit invoked by an admin
DEPOSIT - an automatic increase in credit from user deposits

These types should be in an enum or something

create a method getUserBalanceById(user_id) to get the user's balance of both currencies by user_id, just use SUM() on balance fields for all tx by user_id
create a method add(allRequiredFields) to add a tx - include some sanity checks and validation in this function, i.e. no negative balances, make sure a user has the funds, make sure if the transaction type is an increase the balance change is positive, if a decrease negative, no decimals
create a method getRecent(n) to get the n most recent transactions
create a method getWhales(n, currency) to get the n top users by balance of each currency

create a method liabilities(currency) to get the total amount of currency owed to users by the store

the transactions table will track multi-currency balance changes on users each row in the table has the user_id sats_balance cents_balance, and metadata a transaction has a type one of: CREDIT - a manual increase in credit granted by admin REWARD - an automatic increase in credit applied as a reward REDEEM - a user-consenting or automatic decrease in credit spent on the store or subscription REVOKE - a manual decrease in credit invoked by an admin DEPOSIT - an automatic increase in credit from user deposits These types should be in an enum or something create a method `getUserBalanceById(user_id)` to get the user's balance of both currencies by user_id, just use SUM() on balance fields for all tx by user_id create a method `add(allRequiredFields)` to add a tx - include some sanity checks and validation in this function, i.e. no negative balances, make sure a user has the funds, make sure if the transaction type is an increase the balance change is positive, if a decrease negative, no decimals create a method `getRecent(n)` to get the n most recent transactions create a method `getWhales(n, currency)` to get the n top users by balance of each currency create a method `liabilities(currency)` to get the total amount of currency owed to users by the store
null closed this issue 2025-02-14 23:19:35 -05:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: null/ecomm-store#1
No description provided.