Skip to content

Wallet transaction

Purpose

TBD by human

Identity & key fields

  • Primary key: id (uuid, default gen_random_uuid()).
  • walletId (uuid, NOT NULL, FK → wallet.wallet.id, on-delete cascade).
  • type (enum transaction_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 (enum transaction_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

  • walletId ON DELETE CASCADE; performedBy ON DELETE SET NULL (enforced in tktspace-backend/libs/shared/data-access-db/src/lib/schema/wallet.schema.ts).
  • walletId, type, amount, balanceBefore, balanceAfter, sourceType, createdAt NOT 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) — walletIdwallet.wallet.id, on-delete cascade. N:1.
  • User (operator) (ENT-021) — performedByusers.users.id, on-delete set null. N:1, optional.
  • sourceId polymorphic id — refers to a payment, booking, etc.; resolved application-side via sourceType.

API surfaces

SurfaceExposedNotes
clientyes — /me/wallet/{companyId}/transactions (WalletTransactionItemDto, WalletTransactionsResponseDto)Swagger UI
businessinferred yes — visible from the business panel; managed via libs/features/wallet/src/lib/wallet-admin.module.tsSwagger UI
super-adminno

Known gotchas / open questions

  • balanceBefore/balanceAfter are snapshotted per schema comment — to support auditing without recomputing the running sum. They must agree with wallets.balance after the row is committed.
  • Polymorphic sourceId — no DB-level FK; readers must trust sourceType.
  • The wallet/sources enum and the Payment gateway record are two different ledgers (gateway-level vs internal balance) that should reconcile.