Skip to content

TLabTech/API-Insurance-Policy

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Discord Backers Sponsors Donate


Description

Nest framework TypeScript starter repository.


πŸš€ Project Setup (Local)

1. Install dependencies

npm install

2. Run the project

# development
npm run start

# watch mode
npm run start:dev

# production
npm run start:prod

🐳 Running with Docker

This project includes a full Docker setup for NestJS + PostgreSQL + TypeORM migrations & seeders.

1. Build and start containers

docker compose up -d

This command will:

  • Start the NestJS app container (insurance_policy_app)
  • Start the PostgreSQL container (insurance_policy_postgres)

2. Run database migrations

docker compose run --rm migrate

This will execute all pending TypeORM migrations inside the container.

3. Run database seeders

docker compose run --rm seed

Runs the seeders defined in src/db/seeders/ (e.g. role.seeder.ts, user.seeder.ts, etc.).

4. Verify containers

docker compose ps

You should see something like:

insurance_policy_postgres   Up   0.0.0.0:5432->5432/tcp
insurance_policy_app        Up   0.0.0.0:3000->3000/tcp

5. Access the application

Once containers are up, the app is available at:

http://localhost:3000

6. Access Swagger API docs

http://localhost:3000/api

7. Stop all containers

docker compose down

To reset all data (remove database volume):

docker compose down -v

πŸ—„οΈ Database Management

Database Migrations

Script Command Description
npm run migration:generate <name> Generate new migration Creates a migration from entity changes
npm run migration:create <name> Create empty migration Creates an empty migration file
npm run migration:run Run migrations Executes pending migrations
npm run migration:revert Revert migration Reverts the last executed migration
npm run migration:show Show migrations Lists all migrations and their status

Example:

npm run migration:generate src/db/migrations/AddUserColumn
npm run migration:run

🧠 Note: In Docker, you can also run migrations using:

docker compose run --rm migrate

Database Seeders

Seeders populate initial data in the application.

Available Seeder Commands

# Local (requires npm dependencies)
npm run seed
npm run seed:dev

# Dockerized environment
docker compose run --rm seed

Seeder Flow

  1. role.seeder.ts β†’ create default roles
  2. user.seeder.ts β†’ create admin & default users
  3. All seeders registered in main.seeder.ts

πŸ“œ API Documentation

Once running, Swagger is available at:

http://localhost:3000/api

Features

  • JWT Authentication
  • File Upload (JPEG, PNG, PDF)
  • CORS Enabled
  • Validation using class-validator

🧰 Development Notes

Environment Files

  • .env is automatically loaded into Docker containers.
  • Example configuration:
    DB_HOST=db
    DB_PORT=5432
    DB_USERNAME=postgres
    DB_PASSWORD=postgres
    DB_NAME=insurance_policy_db

Volume Persistence

Database data is stored in Docker volume pgdata:

docker volume ls

To clear database data:

docker compose down -v

βœ… Production Checklist

  • synchronize: false in data-source.ts
  • Test migrations before deployment
  • Backup production DB before running migrations
  • Use strong passwords & secrets
  • Set proper CORS origins
  • Enable HTTPS in production

🧠 Quick Summary

Task Local Command Docker Command
Run App npm run start:dev docker compose up -d
Run Migrations npm run migration:run docker compose run --rm migrate
Run Seeders npm run seed:dev docker compose run --rm seed
Stop All Ctrl + C docker compose down

License

Nest is MIT licensed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors