Skip to content

Sany8k/marketplace_api

Repository files navigation

Marketplace API

REST API for a marketplace built with NestJS using TypeScript and PostgreSQL.

Table of Contents


API Demo

The following demo shows:

  • application startup
  • authentication flow
  • protected endpoints
  • basic CRUD operations

POST /authentication/sign-Up { "name": "TestName", "email": "user@mail.com", "password": "secret" }

POST /authentication/sign-In { "email": "user@mail.com", "password": "secret" }

{ "accessToken": "eyJhbGciOiJIUzI1NiIs...", "refreshToken": "eyJhbGciOiJIUzI1NiIs..." }


Prerequisites

This project requires a running PostgreSQL database. The application will not start without a database connection.

Option 1: Run PostgreSQL with Docker (recommended)

docker-compose up -d

Installation

Clone the repository:

git clone https://github.com/Sany8k/marketplace_api.git
cd marketplace_api

Install dependencies:

npm install

Create a .env file based on .env.example and configure database connection, JWT secret, and other variables.


Running the Project

Start in development mode:

npm install -g @nestjs/cli
nest start --watch

or

npm run start:dev

Build and run for production:

node dist/main

Testing

Unit tests

Unit tests are located next to the source files inside the src/ directory and are implemented using Jest and @nestjs/testing.


Project Structure

src/
β”œβ”€β”€ cart/            # Cart module
β”œβ”€β”€ categories/      # Categories module
β”œβ”€β”€ iam/             # Authentication and authorization (JWT)
β”œβ”€β”€ products/        # Products module
β”œβ”€β”€ users/           # Users module
└── main.ts          # Entry point

Technologies Used

NestJS

TypeScript

PostgreSQL

TypeORM

JWT

Docker

Bcrypt

class-validator

Swagger


API Endpoints

Users

Method Route Description
GET /users Get all users
GET /users/me Get the authenticated user
PATCH /users/:id Update user as admin
PATCH /users/me Update the authenticated user
DELETE /users/:id Delete a user

Authentication

Method Route Description
POST /authentication/sign-Up Create a new account
POST /authentication/sign-In Login to an existing account
POST /authentication/refresh-tokens Refresh JWT token

Products

Method Route Description
GET /products Get all products
GET /products/filter Get products with query filters
GET /products/:id Get a product by ID
PATCH /products/:id Update a product by ID (admin)
POST /products/create-product Create a new product
POST /products/wishlist/:id Add product to wishlist
DELETE /products/:id Delete a product by ID
DELETE /products/wishlist/:id Remove product from wishlist

Categories

Method Route Description
GET /categories Get all categories
GET /categories/:id Get a category by ID
PATCH /categories/:id Update category as admin by ID
POST /categories Create a category (admin)
DELETE /categories/:id Delete a category (admin)

Cart

Method Route Description
GET /cart Get all products in cart
POST /cart Add product to cart
DELETE /cart Delete all products from cart
DELETE /cart/:id Delete a product by ID from cart

For detailed API documentation, visit Swagger UI at: http://localhost:3000/api


Authentication & Authorization

JWT-based authentication

/authentication/sign-Up and /authentication/sign-In endpoints

Protected routes use AuthGuard and role-based checks


License

MIT License

About

πŸ›’ Marketplace API (NestJS + PostgreSQL + TypeORM)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors