Skip to main content

Rewards

Overview

The rewards module manages channel rewards (e.g., Twitch Channel Points) with full CRUD operations. Each reward is scoped to an account and platform, with an optional link to the platform's native reward ID. Rewards carry a configurable action JSONB field that defines what happens when the reward is redeemed.

Architecture

Dashboard UI
|
v
Next.js API Proxy (/api/rewards)
|
v
GraphQL (RewardQuery / RewardMutation)
|
v
db::rewards (PostgreSQL)

Rewards are stored in the channel_rewards table and can be synced with external platform reward systems via the platform_reward_id field. The action JSONB field allows flexible behavior configuration without schema changes.

API

GraphQL Queries

QueryArgsReturnsPermission
rewards--[Reward]rewards:read
rewardid: UUIDReward?rewards:read
  • rewards returns all rewards for the active account, ordered by created_at ASC.
  • reward returns a single reward by ID, filtered by account ownership.

GraphQL Mutations

MutationArgsReturnsPermission
createRewardinput: CreateRewardInputRewardrewards:create
updateRewardinput: UpdateRewardInputRewardrewards:edit
deleteRewardid: UUIDDeleteRewardResultrewards:delete

All mutations verify account ownership before proceeding.

GraphQL Types

type Reward {
id: UUID!
accountId: UUID!
platform: String!
platformRewardId: String
title: String!
cost: Int
enabled: Boolean!
action: JSON!
createdAt: String!
updatedAt: String!
}

input CreateRewardInput {
platform: String!
platformRewardId: String
title: String!
cost: Int
action: JSON
}

input UpdateRewardInput {
id: UUID!
title: String
cost: Int
enabled: Boolean
action: JSON
}

type DeleteRewardResult {
success: Boolean!
}

REST Endpoints

Rewards are currently exposed only via GraphQL. There is no dedicated /v1/rewards REST resource; to CRUD rewards from an external script, use GraphQL directly.

Action JSONB

The action field is a flexible JSONB object that defines reward behavior. It defaults to {} if not provided during creation. The structure is application-defined and can vary per use case (e.g., trigger an overlay alert, play a sound, enable a chat mode).

Permissions

PermissionDescription
rewards:readList and view rewards
rewards:createCreate new rewards
rewards:editUpdate existing rewards
rewards:deleteDelete rewards

Included in: Owner, Administrator roles. Moderator and Viewer roles have rewards:read only.

Database

Table: channel_rewards

ColumnTypeDescription
idUUID (PK)Reward ID
account_idUUID (FK)Owning account
platformTEXTPlatform identifier (e.g., twitch)
platform_reward_idTEXTExternal platform reward ID (for sync)
titleTEXTReward display title
costINTPoint cost (nullable)
enabledBOOLEANWhether the reward is active
actionJSONBConfigurable reward action payload
created_atTIMESTAMPTZCreation timestamp
updated_atTIMESTAMPTZLast update timestamp

DB Functions

FunctionDescription
list_rewardsList all rewards for an account, ordered by created_at ASC
get_rewardGet a single reward by ID
create_rewardInsert a new reward
update_rewardPartial update using COALESCE for optional fields
delete_rewardDelete by ID, returns whether a row was deleted

Key Files

FilePurpose
apps/api/src/graphql/rewards.rsGraphQL queries, mutations, input/output types
apps/api/src/db/rewards.rsDatabase CRUD operations
crates/lo-auth/src/rbac.rsPermission constants (rewards:read/create/edit/delete)