Defining Support Ticket Models
Welcome to the Support Ticket API
Welcome! In this first lesson, you’ll get familiar with the support ticket backend that you’ll develop throughout the course. The project uses TypeScript, Express 5, and PostgreSQL, with an API Simulator available in the preview panel for sending requests and inspecting responses.
You’ll begin by understanding the Ticket domain model, then follow a request through the Express route and PostgreSQL repository. Finally, you’ll configure the API Simulator with the backend’s base URL and use it to verify the database connection and retrieve the current tickets.
Why Database-Backed APIs Matter
Database-backed APIs let client applications store and retrieve shared information that must survive beyond a single request or server restart. They provide a controlled path between HTTP clients and persistent data, supporting common systems such as help desks, order tracking, account management, and dashboards. Learning this pattern helps you build services that return reliable, shared data instead of temporary in-memory results.
Understanding the Project Flow
The application separates its responsibilities across several small, focused files. A request to GET /api/tickets enters the Express router in src/routes/ticket-routes.ts, which calls the repository in src/repositories/ticket-repository.ts. The repository queries PostgreSQL, converts database rows into application-friendly Ticket objects, and returns them to the route as JSON.
The central files used in this flow are:
src/domain/ticket.ts, which defines the ticket values and TypeScript types.src/repositories/ticket-repository.ts, which communicates with PostgreSQL and maps database rows.src/routes/ticket-routes.ts, which exposes the ticket-listing endpoint.src/routes/health-routes.ts, which checks whether PostgreSQL is reachable.src/app.ts, which configures Express and mounts the routers.
Keeping these responsibilities separate will make the API easier to extend as you later add validation, authentication, authorization, workflow actions, and additional database operations.
Defining the Allowed Ticket Values
The domain model lives in src/domain/ticket.ts. It begins with two constant arrays that define every status and priority currently supported by the application.
-
ticketStatusescontains the three stages recognized by the ticket workflow. A ticket can begin as"open", move to"in_progress", and eventually become"closed". -
ticketPrioritieslimits priority to"low","medium", or"high". Using one shared list prevents different parts of the application from inventing incompatible values such as"urgent"or"normal". -
The
as constassertion tells TypeScript to preserve each item as a specific string literal. Without it, TypeScript would usually infer these values as a generalstring[], which would be too broad for the domain model.
These constants are useful at runtime because the application can inspect or validate against them. They also become the source for the TypeScript types used throughout the project.

