Skip to content

kfkkail/price-list-manager-api

Repository files navigation

Price List Manager API

A simple and modern TypeScript API for managing price lists built with Node.js, Express, and PostgreSQL.

🚀 Features

  • Full CRUD operations for price lists
  • TypeScript for type safety and better development experience
  • PostgreSQL database with automatic timestamp management
  • RESTful API design
  • Input validation and error handling
  • Security middleware (Helmet, CORS)
  • Database migrations and seeding

🛠️ Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Language: TypeScript
  • Database: PostgreSQL
  • Package Manager: Yarn

📋 Prerequisites

  • Node.js (v16 or higher)
  • Yarn package manager
  • Docker (for PostgreSQL database)

🚀 Quick Start

The easiest way to get started is using the automated setup script:

git clone <your-repo-url>
cd price-list-manager-api
./setup.sh

This script will:

  • Start PostgreSQL database using Docker
  • Create your .env file with correct credentials
  • Install dependencies
  • Set up the database tables
  • Seed with sample data
  • Give you instructions to start the dev server

Quick Development Start

If you just want to start developing immediately:

./dev-start.sh

This will:

  • Check if .env exists (create if needed)
  • Start PostgreSQL if not running
  • Launch the development server

Edit .env with your PostgreSQL credentials (the setup script handles this automatically):

DB_HOST=localhost
DB_PORT=5432
DB_NAME=price_list_db
DB_USER=postgres
DB_PASSWORD=postgres
PORT=3001
NODE_ENV=development

The API will be available at http://localhost:3001

📚 API Endpoints

Health Check

  • GET /health - Check API status

Price Lists

  • GET /api/price-lists - Get all price lists
  • GET /api/price-lists/:id - Get a specific price list
  • POST /api/price-lists - Create a new price list
  • PUT /api/price-lists/:id - Update a price list
  • DELETE /api/price-lists/:id - Delete a price list

📝 API Examples

Create a Price List

curl -X POST http://localhost:3001/api/price-lists \
  -H "Content-Type: application/json" \
  -d '{"name": "Summer Sale Pricing"}'

Get All Price Lists

curl http://localhost:3001/api/price-lists

Update a Price List

curl -X PUT http://localhost:3001/api/price-lists/1 \
  -H "Content-Type: application/json" \
  -d '{"name": "Updated Summer Sale Pricing"}'

Test Structure: Tests are co-located with source files (e.g., priceList.test.ts next to PriceList.ts)

Daily Development Workflow

# Start your day
./dev-start.sh

# Run tests
yarn test:watch

# Fix linting issues
yarn lint:fix

# Stop everything
docker-compose down

🔧 Development

Project Structure

src/
├── controllers/     # Request handlers + tests
├── database/        # Database config, migrations + tests
├── models/          # Data models + tests
├── routes/          # API route definitions
├── types/           # TypeScript type definitions
└── server.ts        # Main application file

Development Tips

  • Use ./setup.sh for first time setup
  • Use ./dev-start.sh for daily development - it handles everything automatically
  • Run yarn test frequently to catch issues early
  • Use yarn lint:fix to automatically fix code style issues
  • Check http://localhost:3001/health to verify the API is running

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published