This project provides a Customer Support API for managing tickets and messages.
To get the project up and running, follow these steps:
-
Clone the repository:
git clone <repository_url> cd customer-support-api
-
Start Docker Compose:
This will build the Docker images and start the PostgreSQL database and the Node.js application.
docker-compose up --build
-
Run Database Migrations: (Optional)
After the services are up, run the database migrations to create the necessary tables.
docker-compose exec customer-support-api yarn migrate:up
Here's a list of the available API endpoints and their usage:
-
POST /ticket- Description: Creates a new support ticket.
- Request Body:
{ "customer_name": "string", "customer_email": "string", "description": "string" }
-
GET /ticket- Description: Retrieves a list of all support tickets.
-
GET /ticket/:id- Description: Retrieves a single support ticket by its ID.
-
PATCH /ticket/:id/resolve- Description: Resolves a support ticket by its ID.
-
POST /ticket-message/:id- Description: Creates a new message for a specific ticket.
- Request Body:
{ "message": "string", "sender": "string" (e.g., "customer", "agent") }
-
PATCH /ticket-message/:id- Description: Updates an existing message for a specific ticket.
- Request Body:
{ "message": "string" }
-
PATCH /ticket-message/:id/publish- Description: Publishes a ticket message (e.g., marks it as visible to the customer).
GET /health- Description: Returns the health status of the API.
To create a new migration script (for example, to add a new table), run the following command inside the Docker container:
docker-compose exec customer-support-api yarn migrate:create <migration_name>Replace <migration_name> with a descriptive name for your migration, such as create-users-table.
This will generate a new migration file in the migrations directory.
To run database migrations from inside the Docker container, use the following command:
docker-compose exec customer-support-api yarn migrate:upThis will execute the migration script within the running customer-support-api service container, ensuring it can connect to the database service.