Skip to content

Rime-Islam/tech-tips-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backend API Documentation

Live Demo

This is the backend of the application built with Express.js, TypeScript, Mongoose, and various validations for handling different routes and user actions.

Project Setup

Prerequisites

Make sure you have the following installed:

  • Node.js (version 14.x or above)
  • MongoDB (running locally or using a cloud database like MongoDB Atlas)

Installation

  1. Clone the repository:
    git clone https://github.com/bashputi/tech-tips-backend
    

Navigate to the project directory:

cd your-project-name

Install dependencies:

Copy code
npm install

Create a .env file in the root directory and set the required environment variables:

PORT=use-yours
DB_URL=use-yours
BCRYPT_SALT_ROUND=10
ACCESS_TOKEN_SECRET=use-yours
ACCESS_REFRESH_SECRET=use-yours
NODE_ENV=use-yours
FRONTEND_URL=use-yours
EMAIL_USER=use-yours
EMAIL_PASS=use-yours
STORE_ID=use-yours
SIGNATURE_KEY=use-yours
PAYMENT_URL=use-yours
PAYMENT_TRANSACTION=use-yours
BACKEND_URL=use-yours

Run the development server:

npm start

Your API will be available at http://localhost:"your-port".

Routes

  • Auth Routes (/auth)
  • POST /signup: Register a new user
  • POST /signin: Sign in with existing credentials
  • POST /forget_password: Request password reset
  • POST /reset_password: Reset password using a token

Example Usage:

Register a user:

  1. Auth Routes (/auth)
  • POST /auth/signup: Register new user.
{
  "email": "user@example.com",
  "password": "password123"
}
  1. User Routes (/user)
  • GET /: Get all users (Admin only)
  • GET /: Get a single user by userId
  • PATCH /: Update a user by userId
  • PATCH /user/follow/: userId
  • PATCH /follow/: Follow a user (Authenticated users only)
  • GET /follower/: Get a user's followers

Example Usage:

Follow a user:

  1. Post Routes (/post)
  • POST /create: Create a new post
  • GET /: Get all posts
  • GET /my-post: Get posts of the authenticated user (User/ Admin only)
  • GET /: Get a single post by postId
  • GET /category: Get posts by category
  • PATCH /update-post/: Update a post (User only)
  • DELETE /delete/: Delete a post (User only)
  • POST /comments/: Add a comment to a post (User/ Admin only)
  • PATCH /update-comments/: Update a comment (User/ Admin only)
  • DELETE /comment-delete/: Delete a comment (User/ Admin only)
  • PATCH /vote/: Upvote a post (User/ Admin only)
  • POST /payment/: Handle user payment

Example Usage:

Create a post:

  • POST /post/create
{
  "title": "Post Title",
  "content": "Post content goes here",
  "category": "Technology"
}

Add a comment:

  • POST /post/comments/:postId: Make a comment into a post.
{
  "comment": "This is a comment"
}
  1. Payment Routes (/payment)
  • POST /payment/: Handle payments for a user
  • POST /confirmation: Confirm payment after user completes the transaction

Example Usage:

Make a payment:

  • POST /payment/:userId: Subscribe by paying some ammount.
{
  "amount": 20
}

Middleware

  • Authentication Middleware (auth) Used in routes like PATCH /follow/:userId, POST /comments/:postId, POST /payment/:userId, and others that require authentication.

It verifies if the request is coming from an authenticated user, and checks if the user has the correct role (admin or user).

Example Usage in a Route:

typescript Copy code UserRouter.patch("/follow/:userId", auth(user_role.user), UserCrontroller.follow); Where user_role.user checks if the user is authenticated and has the correct role.

Error Handling

All routes are equipped with error handling. If an error occurs, the API will return a proper error response with the status code and error message.

License

  • This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published