Skip to content

A Node RESTful API that manages a blog's users, posts, categories & comments.

Notifications You must be signed in to change notification settings

Ahmed-Yassen/blog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blog App

A Node RESTful API that manages a blog's users, posts, categories & comments.

Technologies Used: Node.js - Nest.js - TypeScript - PostgresSQL - TypeORM.

Features

  • Connect to the Database, Perform CRUD Operations & Create Relationships using TypeORM.
  • Create Environment Variables using Config Module.
  • Validate Data using Validation Pipes & DTOs.
  • Serialize Returned Data using Interceptors & DTOs.
  • Authenticate users with JWT & Cookies using Passport JWT Strategy.
  • Hash Passwords with bcrypt.
  • Authorize Routes with Guards.

Environment Variables

To run this project, you will need to create a .env file in the root directory of the project

JWT_SECRET JWT_EXPIRATION_TIME POSTGRES_USER POSTGRES_PASSWORD POSTGRES_DB ADMIN_EMAIL ADMIN_PASSWORD

Run Locally

Clone the project

  git clone https://github.com/Ahmed-Yassen/blog.git

Go to the project directory

  cd blog

Install dependencies

  npm install

Start the server

  npm run start

API Documentation

-- Auth Routes --

Create a new user

  POST /api/auth/sign-up/
Parameter Type Description
email string Required.
password string Required. should be atleast 8 characters.
firstName string Required.
lastName string Required.

Log user in

  POST /api/auth/sign-in
Parameter Type Description
email string Required.
password string Required.

Log user out (Requires Auth)

  POST /api/auth/sign-out
Parameter Type Description

-- Users Routes --

Get current logged-in user profile (Requires Auth)

  GET /api/users/profile

Change password for current logged-in user (Requires Auth)

  POST /api/users/change-password  
Parameter Type Description
currentPassword string Required.
newPassword string Required.

Remove user account (Requires Auth & Role: admin)

  DELETE /api/users/:id
Parameter Type Description
id number Required. user id

-- Categories Routes -- (Requires Auth & Role: admin)

Create a category

  POST /api/categories
Parameter Type Description
name string Required.

Get all categories

  GET /api/categories

Update a category

  PATCH /api/categories/:id
Parameter Type Description
id number Required.
name string Required.

Remove a category

  DELETE /api/categories/:id
Parameter Type Description
id number Required.

-- Posts Routes -- (Requires Auth)

Create a post

  POST /api/posts
Parameter Type Description
title string Required.
content string Required.
categories array[{id:number}] Required. an array that holds objects that contain the category id of each category of the post

Update a post

  PATCH /api/posts/:id
Parameter Type Description
id number Required.
content string Optional.
title string Optional.
categories array[{id:number}] Optional.

Remove a post

  • Can remove only my posts when role is user
  • Can remove any post when role is admin
  DELETE /api/patients/:id 
Parameter Type Description
id number Required.

Get post by id

  GET /api/posts/find/:id
Parameter Type Description
id number Required. id of the post to find

Get my posts

  GET /api/posts/my-posts

Get a user's posts

  GET /api/posts/user/:id
Parameter Type Description
id number Required. id of a user to find their posts

Get posts in a specific category

  GET /api/posts/category/:id
Parameter Type Description
id number Required. id of the category.

Get newest posts

  GET /api/posts/newest

-- Comments Routes -- (Requires Auth)

Create a comment

  POST /api/comments
Parameter Type Description
content string Required.
postId number Required.

Update a comment

  PATCH /api/comments/:id
Parameter Type Description
id number Required.
content string Required.

Remove a comment

  DELETE /api/comments/:id
Parameter Type Description
id number Required.

Feedback

If you have any feedback, please reach out to me at ahmed.ibrahim.yassen@gmail.com

About

A Node RESTful API that manages a blog's users, posts, categories & comments.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published