Skip to content

codenamerhu/rental-management-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Property Management API

This is a Node.js REST API for managing properties, locations, and user roles (Tenants, Landlords, Agents, and Staff). The API allows CRUD operations for properties and locations and includes features such as user authentication, role-based access control, image uploads to AWS S3, and more. The project follows best practices in structure, architecture, and testing.

Table of Contents

Features

  • User Authentication: Register and login for users with role (Tenant, Landlord, Agent, Staff).
  • Role-Based Access Control: Restrict access based on user roles and staff permissions (SuperUser, Editor, etc.).
  • Property and Location Management: CRUD operations for properties and locations with fields like title, description, price, images, and location details (province, city, suburb, coordinates).
  • Image Upload: Upload and store property images on AWS S3.
  • Forgot Password and OTP Verification: Reset password functionality with email OTP verification.
  • Automated Testing: Unit tests for controllers to ensure code reliability.

Technologies Used

  • Node.js & Express: Backend framework.
  • MongoDB with Mongoose: Database and ODM for schema management.
  • JWT: JSON Web Tokens for authentication.
  • AWS S3: Storage for property images.
  • Jest: Testing framework for unit tests.
  • dotenv: Environment variable management.
  • GitHub Actions: Continuous integration (CI) for running tests automatically on each push.

Getting Started

Prerequisites

  • Node.js >= 16
  • MongoDB
  • AWS S3 account for image uploads

Installation

  1. Clone this repository:

    git clone https://github.com/codenamerhu/property-management-api.git
    cd property-management-api
  2. Install dependencies:

    npm install
  3. Configure environment variables (see Environment Variables).

  4. Start the server:

    npm start

    The server will run at http://localhost:3000.

Project Structure

.
├── src
│   ├── controllers      # Controllers for handling requests
│   ├── models           # Mongoose models for MongoDB
│   ├── routes           # Route definitions
│   ├── middleware       # Authentication and role verification middleware
│   ├── services         # AWS S3 upload and other services
│   └── tests            # Unit tests for controllers
└── README.md

Environment Variables

To run this project, you need to set up the following environment variables in a .env file at the root:

  • General Configuration

    PORT=3000
    MONGODB_URI=your-mongodb-uri
    JWT_SECRET=your-jwt-secret
    
  • AWS Configuration

    AWS_ACCESS_KEY_ID=your-aws-access-key-id
    AWS_SECRET_ACCESS_KEY=your-aws-secret-access-key
    AWS_BUCKET_NAME=your-s3-bucket-name
    

Endpoints

Auth Endpoints

  • POST /auth/register - Register a user with role (Tenant, Landlord, Agent, Staff).
  • POST /auth/login - Login and receive a JWT token.
  • POST /auth/forgot-password - Send OTP for password reset.
  • POST /auth/reset-password - Reset password using OTP.

Property Endpoints

  • POST /properties - Create a property (Landlords/Agents only).
  • GET /properties - Get all properties.
  • GET /properties/:id - Get a single property by ID.
  • PUT /properties/:id - Update a property by ID (requires ownership).
  • DELETE /properties/:id - Delete a property by ID (requires ownership).

Location Endpoints

  • POST /locations - Create a new location.
  • GET /locations - Get all locations.
  • GET /locations/:id - Get a single location by ID.
  • PUT /locations/:id - Update a location.
  • DELETE /locations/:id - Delete a location.

Role-Based Access Control

  • SuperUser: Full access to all features.
  • Editor: Limited access to certain CRUD operations.

Testing

This project uses Jest for testing. You can run tests with:

npm test

Tests include:

  • Authentication tests (registration, login, role validation).
  • Property tests (create, read, update, delete).
  • Location tests (CRUD operations).

Continuous Integration

This project uses GitHub Actions for continuous integration. Each time code is pushed to the repository or a pull request is made, GitHub Actions runs the test suite to ensure code reliability.

You can find the GitHub Actions configuration in .github/workflows/test.yml.

Contribution Guidelines

Contributions are welcome! If you'd like to add a new feature or fix a bug, please follow these guidelines:

  1. Fork the repository and create your branch from main.
  2. Install all dependencies to ensure compatibility.
  3. Write Unit Tests: For any new features or changes, add unit tests to maintain code reliability.
  4. Commit changes with clear messages.
  5. Push your branch and submit a Pull Request.

Please ensure all tests pass in GitHub Actions before submitting your PR.

Future Improvements

  • Add support for advanced search and filtering on properties.
  • Implement pagination for property and location listings.
  • Improve role-based access control with custom permissions.
  • Add more unit and integration tests.

This project is designed to follow best practices in architecture, security, and testability. Contributions are welcome!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published