Backend API for user authentication and issue tracking, built with Node.js, Express, TypeScript, PostgreSQL, and JWT-based authorization.
- Project Name: Assignment Two API
- Live URL:
https://assignment-two-eta-three.vercel.app/ - Local URL:
http://localhost:5000
- User registration with
contributorandmaintainerroles - User login with JWT token generation
- Protected issue creation for authenticated users
- Public issue listing with sorting and filtering
- Public single issue details endpoint
- Role-based issue update permissions
- Maintainer-only issue deletion
- PostgreSQL-backed persistent data storage
- Node.js
- Express.js
- TypeScript
- PostgreSQL
- JWT (
jsonwebtoken) bcryptjspgdotenvtsx
git clone <your-repository-url>
cd "assignment Two"npm installCreate a .env file in the project root and add:
PORT=5000
CONNECTIONSTRING=your_postgresql_connection_string
SECRET=your_jwt_secretnpm run devThe API will run at:
http://localhost:5000
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/auth/signup |
Public | Register a new user |
| POST | /api/auth/login |
Public | Login user and return JWT |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/issues |
Authenticated | Create a new issue |
| GET | /api/issues |
Public | Get all issues with optional filters |
| GET | /api/issues/:id |
Public | Get a single issue by id |
| PATCH | /api/issues/:id |
Authenticated | Update an issue based on role rules |
| DELETE | /api/issues/:id |
Maintainer only | Delete an issue |
GET /api/issues supports:
| Parameter | Values | Default |
|---|---|---|
sort |
newest, oldest |
newest |
type |
bug, feature_request |
none |
status |
open, in_progress, resolved |
none |
Example:
/api/issues?sort=newest&type=bug&status=open
Protected routes require a JWT token in the Authorization header:
Authorization: Bearer <your_token>
The JWT payload includes:
idnameemailrole
| Column | Type | Constraints |
|---|---|---|
id |
SERIAL | Primary key, unique |
name |
VARCHAR(255) | Not null |
email |
VARCHAR(255) | Not null, unique |
password |
VARCHAR(255) | Not null |
role |
VARCHAR(20) | Not null, default contributor |
created_at |
TIMESTAMP | Default current timestamp |
updated_at |
TIMESTAMP | Default current timestamp |
Allowed role values:
contributormaintainer
| Column | Type | Constraints |
|---|---|---|
id |
SERIAL | Primary key, unique |
title |
VARCHAR(150) | Not null |
description |
TEXT | Not null, minimum length 20 |
type |
VARCHAR(20) | Not null |
status |
VARCHAR(20) | Not null, default open |
reporter_id |
INTEGER | Not null |
created_at |
TIMESTAMP | Default current timestamp |
updated_at |
TIMESTAMP | Default current timestamp |
Allowed type values:
bugfeature_request
Allowed status values:
openin_progressresolved
- Contributors can create issues
- Contributors can update only their own issues and only when status is
open - Maintainers can update any issue
- Only maintainers can delete issues
{
"success": true,
"message": "Operation completed successfully",
"data": {}
}{
"success": false,
"message": "Request failed",
"errors": "Error details"
}| Command | Description |
|---|---|
npm run dev |
Start the development server |
- Database tables are initialized automatically when the server starts
- Use Postman or any API client to test protected endpoints
- Replace the live URL placeholder after deployment