Skip to content

Notification

Internals of the Notification domain. For the public API, see Notification API.

Notifications are part of the ticketing lane; chat is a native /api/v1 feature added later to the same Go package (domain/notifications). Checked against CoreAPI staging on 2026-11-16.

How notifications are created

graph LR
    I["Identity"] -->|CreateNotification| N["NotificationService"]
    C["Commerce"] -->|CreateNotification| N
    CA["Catalogue (ticket group, rail menu, banner)"] -->|CreateNotification| N
    A["Advertising, Analytics"] -->|CreateNotification| N
    N --> DB[("johorzoo.notification")]
    Admin["Admin frontend"] -->|/api/:workspaceId/notifications| DB

Other domains call the Go service; there is no HTTP route to create one. This is the "Internal API" section of the old page:

CreateNotification(performedBy, authorityLevel, notificationType, title, message, date, workspaceID string) error
  • workspaceID stamps the row; the organization is resolved from the workspace (ResolveOrganizationForWorkspace). Callers pass SPATIO_TICKETING_WORKSPACE_ID or the ticket group's workspace.
  • Two helpers wrap it with date = now (YYYY-MM-DD HH:MM:SS): one with performer SYSTEM, one with a given performer.
  • type is free text. Values in use: Order, Customer/customer, Ticket Group, Rail Menu, Banner, Password reset, Admin Account Profile. authorityLevel is the actor's role or system/customer; casing is not consistent (CUSTOMER, customer, Customer all occur).
  • List: is_deleted = false AND workspace_id = ?, search ILIKE on title, message, type and performed_by, newest first, limit clamped to 10–100. Update, mark-all-read and delete-all are workspace-scoped; "delete" is a soft delete (is_deleted).
  • Auth: ProtectedRS256 + RequireWorkspacePermission(workspace:notifications:manage) on /api/:workspaceId. The group /api/:workspaceId is broad; register new /api/<word>/… ticketing routes with this in mind.

Chat

  • Wired by notificationsroutes.SetupChat from routes_platform.go (needs OrgService to list org users). Routes in routes/chat_routes.go, all behind ProtectedRS256; the caller is authClaims.UserID and the organization is authClaims.Org.OrgID. No named permission.
  • A direct chat is unique per organization by direct_key (the two user IDs sorted and joined). Group chats have no key and a name; membership changes need the caller to be a participant, and fail with ErrNotGroupChat on direct chats.
  • Message IDs are UUIDv7, so the before cursor doubles as chronological order. ListMessages clamps limit to 1–100 (else 50).
  • Websocket (GET /chat/ws): one connection per user session; Hub (chat_hub.go) keeps connections by user ID and fans a message out to every participant's connections. Browsers can't set headers on a websocket handshake, so ProtectedRS256 falls back to the access_token cookie. Inbound frame {type:"message", chatId, body}; outbound {type:"message"|"error"}. The hub is in-process: with more than one CoreAPI replica, a message is pushed only to sockets on the replica that received it. REST sends and websocket sends use the same SendMessage.

Data model

erDiagram
    Notification {
        uint notification_id
        string organization_id
        string workspace_id
        string performed_by
        string authority_level
        string type
        string title
        text message
        string date
        bool is_read
        bool is_deleted
    }
    Chat {
        uuid id
        string organization_id
        string type
        string direct_key
        string name
        timestamptz last_message_at
    }
    ChatParticipant {
        uuid chat_id
        string user_id
        timestamptz last_read_at
    }
    ChatMessage {
        uuid id
        uuid chat_id
        string sender_id
        text body
    }
    Chat ||--o{ ChatParticipant : has
    Chat ||--o{ ChatMessage : contains

johorzoo.notification; chats, chat_participants and chat_messages in public.

Known issues

  • The old page described GET /api/notifications and PUT /api/notification with no workspace and an { success, data } answer; both were wrong since 2026-09-14 (workspace-scoped, ticketing format).
  • last_read_at on chat_participants is stored but no route reads or sets it: there is no unread count yet.
  • The authority_level and type values are not an enum; the admin UI filters on them as strings.
  • Chat websocket scales to one replica only (see above).

Change history

  • 2026-09-14: notifications scoped to :workspaceId; search and pagination in the workspace.
  • 2026-09-01: group chat and websocket.
  • 2026-08-19: mark all read, delete all.
  • 2026-08-17: direct chat.
  • 2026-06-23: first notification documentation.