Skip to content

A robust NestJS backend API for managing a construction company's admin dashboard. Built with TypeScript, featuring secure authentication, contact management, and project portfolio management.

Notifications You must be signed in to change notification settings

LEO20Debugger/pues-api-node

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 on Open Collective Sponsors on Open Collective Donate us Support us Follow us on Twitter

πŸ—οΈ Construction Company Admin Dashboard API

A robust NestJS backend API for managing a construction company's admin dashboard. Built with TypeScript, featuring secure authentication, contact management, and project portfolio management.

✨ Features

  • πŸ” Secure Authentication: JWT-based authentication with bcrypt password hashing
  • πŸ“ž Contact Management: Store and manage customer inquiries and contact information
  • 🏒 Project Portfolio: Upload and manage construction projects with images and descriptions
  • πŸ“Š Dashboard Analytics: Get overview statistics and recent activities
  • πŸ›‘οΈ Protected Routes: All admin endpoints require authentication
  • βœ… Input Validation: Comprehensive validation using Zod schemas
  • πŸ—„οΈ Database: MySQL with Drizzle ORM for type-safe database operations

πŸš€ Quick Start

Prerequisites

  • Node.js (v18 or higher)
  • MySQL database
  • npm or yarn

Installation

  1. Clone the repository

    git clone <your-repo-url>
    cd pues-api-node
  2. Install dependencies

    npm install
  3. Set up environment variables Create a .env file in the root directory:

    DATABASE_URL=mysql://username:password@localhost:3306/pues_api
    JWT_SECRET=your_super_secret_jwt_key_here_make_it_long_and_random
    PORT=3000
    NODE_ENV=development
  4. Set up the database

    # Generate migrations
    npm run db:generate
    
    # Run migrations
    npm run db:migrate
  5. Start the development server

    npm run start:dev

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

πŸ“š API Documentation

Authentication Endpoints

Create Admin Account

POST /auth/signup
Content-Type: application/json

{
  "email": "admin@construction.com",
  "password": "securepassword123",
  "name": "Admin User"
}

Sign In

POST /auth/signin
Content-Type: application/json

{
  "email": "admin@construction.com",
  "password": "securepassword123"
}

Protected Admin Endpoints

All admin endpoints require a JWT token in the Authorization header:

Authorization: Bearer <your_jwt_token>

Profile Management

GET /admin/profile

Contact Management

GET /admin/contacts          # List all contacts
GET /admin/contacts/:id      # Get specific contact
DELETE /admin/contacts/:id   # Delete contact

Project Management

GET /admin/projects          # List all projects
GET /admin/projects/:id      # Get specific project
POST /admin/projects         # Create new project
PUT /admin/projects/:id      # Update project
DELETE /admin/projects/:id   # Delete project

Dashboard Analytics

GET /admin/dashboard/stats   # Get dashboard statistics

Example: Creating a Project

POST /admin/projects
Authorization: Bearer <token>
Content-Type: application/json

{
  "title": "Modern Office Building",
  "description": "A state-of-the-art office complex with sustainable design",
  "imageUrl": "https://example.com/project-image.jpg",
  "completedAt": "2024-01-15T00:00:00.000Z"
}

πŸ› οΈ Development

Available Scripts

# Development
npm run start:dev          # Start in watch mode
npm run start:debug        # Start with debug

# Production
npm run build              # Build the application
npm run start:prod         # Start production server

# Database
npm run db:generate        # Generate database migrations
npm run db:migrate         # Run database migrations
npm run db:studio          # Open Drizzle Studio

# Testing
npm run test               # Run unit tests
npm run test:e2e           # Run end-to-end tests
npm run test:cov           # Run tests with coverage

# Code Quality
npm run lint               # Run ESLint
npm run format             # Format code with Prettier

Project Structure

src/
β”œβ”€β”€ auth/                  # Authentication module
β”‚   β”œβ”€β”€ auth.controller.ts # Auth endpoints
β”‚   β”œβ”€β”€ auth.service.ts    # Auth business logic
β”‚   β”œβ”€β”€ jwt.strategy.ts    # JWT authentication
β”‚   └── auth.module.ts     # Auth module config
β”œβ”€β”€ admin/                 # Admin dashboard module
β”‚   β”œβ”€β”€ admin.controller.ts # Admin endpoints
β”‚   β”œβ”€β”€ admin.service.ts    # Admin business logic
β”‚   └── admin.module.ts     # Admin module config
β”œβ”€β”€ db/                    # Database configuration
β”‚   β”œβ”€β”€ index.ts           # Database connection
β”‚   β”œβ”€β”€ schema.ts          # Database schema
β”‚   └── database.module.ts # Database module
└── utils/                 # Utility functions
    β”œβ”€β”€ zod-validation.pipe.ts
    └── zod-exception.filters.ts

πŸ”’ Security Features

  • Password Hashing: bcrypt with 12 salt rounds
  • JWT Tokens: 24-hour expiration for admin sessions
  • Input Validation: Zod schemas for all inputs
  • Protected Routes: Authentication required for admin endpoints
  • Soft Deletes: Safe deletion (marked as deleted, not removed)
  • Error Handling: Proper error responses for invalid requests

πŸ—„οΈ Database Schema

Admin Users

  • id: Primary key
  • email: Unique email address
  • passwordHash: Hashed password
  • name: Admin user name
  • createdAt, updatedAt: Timestamps
  • deleted, deletedAt: Soft delete fields

Projects

  • id: Primary key
  • title: Project title
  • description: Project description
  • imageUrl: Project image URL
  • completedAt: Completion date
  • updatedAt: Last update timestamp
  • deleted, deletedAt: Soft delete fields

Contacts

  • id: Primary key
  • name: Contact name
  • email: Contact email
  • phone: Contact phone (optional)
  • message: Contact message
  • createdAt: Contact creation timestamp
  • updatedAt: Last update timestamp
  • deleted, deletedAt: Soft delete fields

πŸš€ Deployment

Environment Variables for Production

DATABASE_URL=mysql://user:password@host:port/database
JWT_SECRET=your_production_jwt_secret
NODE_ENV=production
PORT=3000

Database Migration

npm run db:migrate

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

For support and questions:

  • Create an issue in the repository.
  • Check the AUTH_SETUP.md for detailed setup instructions.

About

A robust NestJS backend API for managing a construction company's admin dashboard. Built with TypeScript, featuring secure authentication, contact management, and project portfolio management.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published