Wallet transaction
Purpose
TBD by human
Identity & key fields
- Primary key:
id(uuid, defaultgen_random_uuid()). walletId(uuid, NOT NULL, FK →wallet.wallet.id, on-delete cascade).type(enumtransaction_type:TOP_UP,DEBIT,REFUND,MANUAL_CREDIT,MANUAL_DEBIT).amount(decimal 10,2, NOT NULL).balanceBefore,balanceAfter(decimal 10,2, NOT NULL) — ledger snapshot per schema comment (“audit without recomputation”).sourceType(enumtransaction_source:LIQPAY,MONO,BOOKING,MEMBERSHIP,MANUAL).sourceId(nullable uuid) —payment.id,booking.id, etc.; NULL for MANUAL operations.performedBy(nullable uuid, FK →users.users.id, on-delete set null) — populated for MANUAL_CREDIT / MANUAL_DEBIT.description(nullable text).createdAt(timestamp, NOT NULL).
business meaning: TBD by human
Invariants
walletIdON DELETE CASCADE;performedByON DELETE SET NULL (enforced in tktspace-backend/libs/shared/data-access-db/src/lib/schema/wallet.schema.ts).walletId,type,amount,balanceBefore,balanceAfter,sourceType,createdAtNOT NULL (enforced in tktspace-backend/libs/shared/data-access-db/src/lib/schema/wallet.schema.ts).
business invariants: TBD by human
Lifecycle
Append-only. No status column.
Relationships
- Wallet (ENT-040) —
walletId→wallet.wallet.id, on-delete cascade. N:1. - User (operator) (ENT-021) —
performedBy→users.users.id, on-delete set null. N:1, optional. sourceIdpolymorphic id — refers to a payment, booking, etc.; resolved application-side viasourceType.
API surfaces
| Surface | Exposed | Notes |
|---|---|---|
| client | yes — /me/wallet/{companyId}/transactions (WalletTransactionItemDto, WalletTransactionsResponseDto) | Swagger UI |
| business | inferred yes — visible from the business panel; managed via libs/features/wallet/src/lib/wallet-admin.module.ts | Swagger UI |
| super-admin | no | — |
Known gotchas / open questions
balanceBefore/balanceAfterare snapshotted per schema comment — to support auditing without recomputing the running sum. They must agree withwallets.balanceafter the row is committed.- Polymorphic
sourceId— no DB-level FK; readers must trustsourceType. - The wallet/
sourcesenum and the Payment gateway record are two different ledgers (gateway-level vs internal balance) that should reconcile.