Prizes & Transactions

Prizes & Transactions

Two small backend services that support the companion app's gamification system: a prize catalog and a credit transaction ledger.


Prizes Service

A CRUD service for managing prizes that attendees can redeem with points earned through quests and interactions.

Service: services/prizes/ (biztechApi-prizes)

Endpoints

All endpoints require Cognito authentication:

MethodPathHandlerDescription
GET/prizes/getAllList all prizes
POST/prizes/createCreate a prize
PATCH/prizes/{id}updateUpdate a prize
DELETE/prizes/{id}delDelete a prize

Prize Data Model

Table: biztechPrizes (primary key: id)

FieldTypeRequiredNotes
idStringYesUnique identifier
nameStringYesDisplay name
priceNumberYesCost in credits
imageHashStringNoImage reference
linksListNoRelated links
createdAtNumberAutoTimestamp
updatedAtNumberAutoTimestamp

How It Works

  • create validates required fields (id, name, price), checks for duplicate id, and inserts with createdAt/updatedAt timestamps
  • update validates the prize exists, then applies a partial update (only fields present in the body)
  • del validates the prize exists, then deletes it
  • getAll does a full table scan — there's no pagination since the prize catalog is always small

Transactions Service

A credit transaction ledger that tracks points earned and spent through companion app activities.

Service: services/transactions/ (biztechApi-transactions)

Endpoints

Both endpoints require Cognito authentication:

MethodPathHandlerDescription
GET/transactions/getAllList transactions (optionally by user)
POST/transactions/createRecord a new transaction

Transaction Data Model

Table: biztechTransactions (primary key: id)

FieldTypeRequiredNotes
idStringAutoUUID (auto-generated)
userIdNumberYesUser identifier
reasonStringYesDescription of what earned/spent the credits
creditsNumberYesPositive = earned, negative = spent

How It Works

Creating a transaction:

  1. Validates required fields (userId, reason, credits)
  2. Checks the user exists in biztechUsers — returns 404 if not found
  3. Generates a UUID (retries until unique — collision check against existing records)
  4. If credits < 0 (spending): checks the user has sufficient balance by scanning all their transactions and summing credits. Returns 202 (insufficient funds) if balance would go negative
  5. Inserts the transaction record

Querying transactions:

  • Without userId query param: full table scan, returns raw array
  • With ?userId=: filters transactions for that user, returns { count, transactions, totalCredits } where totalCredits is the sum of all credit values

Balance Is Computed, Not Stored

There is no cached balance field. Every balance check scans all of a user's transactions and sums the credits values at query time. This works for the current scale but would need optimization for high-volume usage.


How These Fit Into the Companion App

The prize and transaction services support the companion app's gamification loop:

Attend event → Check inComplete quests → Earn credits → Browse prizes → Redeem
                                │                                    │
                                ▼                                    ▼
                    POST /transactions/              GET /prizes/
                    { credits: +100,                 (browse catalog)
                      reason: "quest-x" }
                                                     POST /transactions/
                                                     { credits: -500,
                                                       reason: "prize-y" }

Credits are earned through:

  • Quest completion (scanning QR codes at booths, attending talks)
  • Making connections (NFC taps)
  • Other companion app activities

Credits are spent on prizes from the catalog.


DynamoDB Tables

TableServicePrimary KeyNotes
biztechPrizesPrizesidPrize catalog
biztechTransactionsTransactionsid (UUID)Credit ledger
biztechUsersTransactions (read-only)id (email)User existence check

Key Files

FilePurpose
services/prizes/handler.jsPrize CRUD handlers
services/transactions/handler.jsTransaction create/list handlers
services/prizes/serverless.ymlPrize service config
services/transactions/serverless.ymlTransaction service config

Previous
Overview