{"id":25309997,"url":"https://github.com/developer-shourav/dev-story-backend","last_synced_at":"2025-06-18T21:34:55.343Z","repository":{"id":276839360,"uuid":"923011728","full_name":"developer-shourav/dev-story-backend","owner":"developer-shourav","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-22T20:17:15.000Z","size":125,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T11:11:30.618Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/developer-shourav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-27T13:48:48.000Z","updated_at":"2025-02-22T20:17:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"5357edca-c72a-458c-a3a0-81e3ee71f41e","html_url":"https://github.com/developer-shourav/dev-story-backend","commit_stats":null,"previous_names":["developer-shourav/dev-story-backend"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/developer-shourav/dev-story-backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer-shourav%2Fdev-story-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer-shourav%2Fdev-story-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer-shourav%2Fdev-story-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer-shourav%2Fdev-story-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/developer-shourav","download_url":"https://codeload.github.com/developer-shourav/dev-story-backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer-shourav%2Fdev-story-backend/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260637269,"owners_count":23040090,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-13T13:34:53.659Z","updated_at":"2025-06-18T21:34:50.329Z","avatar_url":"https://github.com/developer-shourav.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome To DevStory\n\n## Live URL\n\nYou can access the live application here: [DevStory Backend](https://dev-story-backend.vercel.app/)\n\n---\n\n## Table of Contents\n\n1. [Introduction](#introduction)\n2. [Features](#features)\n3. [Technologies Used](#technologies-used)\n4. [API Documentation](#api-documentation)\n5. [Project Overview Video](#project-overview-video)\n\n---\n\n## Introduction\n\nDevStory is a blogging platform where users can create, update, and delete their blogs. The platform supports role-based access control with two roles: **Admin** and **User**. Users can manage their own blogs, while admins can manage users and their blogs. The application provides authentication, authorization, and a public API for viewing blogs with search, sort, and filter functionalities.\n\n---\n\n## Features\n\n- User authentication \u0026 authorization (JWT-based authentication)\n- Role-based access control (Admin \u0026 User)\n- CRUD operations for blogs\n- Admin can manage users (block users, delete blogs)\n- Public API for fetching blogs with search, sorting, and filtering\n- Secure password hashing using bcrypt\n- Input validation using Zod\n- Consistent error handling\n- Well-structured REST API following best practices\n\n---\n\n## Technologies Used\n\n- **Backend Framework:** Node.js + Express.js\n- **Language:** TypeScript\n- **Database:** MongoDB with Mongoose\n- **Validation:** Zod\n- **Authentication:** JSON Web Token (JWT)\n- **Security:** Bcrypt for password hashing\n- **Environment Management:** Dotenv\n- **CORS Handling:** CORS\n- **Code Formatting \u0026 Linting:** ESLint, Prettier\n\n---\n\n## API Documentation\n\n### 1. Register User\n\n- **Endpoint:** `/api/auth/register`\n- **Method:** `POST`\n\n**Request Body:**\n\n```json\n{\n  \"name\": \"John Doe\",\n  \"email\": \"john@example.com\",\n  \"password\": \"securepassword\"\n}\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"message\": \"User registered successfully\",\n  \"statusCode\": 201,\n  \"data\": {\n    \"_id\": \"67b63aefc6a46e7f5a8bd22c\",\n    \"name\": \"John Doe\",\n    \"email\": \"john@example.com\"\n  }\n}\n```\n\n### 2. Login User\n\n- **Endpoint:** `/api/auth/login`\n- **Method:** `POST`\n\n**Request Body:**\n\n```json\n{\n  \"email\": \"john@example.com\",\n  \"password\": \"securepassword\"\n}\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"message\": \"Login successful\",\n  \"statusCode\": 200,\n  \"data\": {\n    \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2N2I0YmRkODY2YzQ3ZjViM2NlMWY4YjEiLCJ1c2VyRW1haWwiOiJqb2huQGV4YW1wbGUuY29tIiwicm9sZSI6InVzZXIiLCJpYXQiOjE3Mzk5OTU5NDksImV4cCI6MTc0MDI1NTE0OX0.pkzeYlwlJMZShndN_EZnAEPD3xRbd0dogGlRTN6UDI4\"\n  }\n}\n```\n\n### 3. Create Blog\n\n- **Endpoint:** `/api/blogs`\n- **Method:** `POST`\n- **Requires Authentication** (`Authorization: Bearer \u003ctoken\u003e`)\n\n**Request Body:**\n\n```json\n{\n  \"title\": \"My First Blog\",\n  \"content\": \"This is the content of my blog.\"\n}\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"message\": \"Blog created successfully\",\n  \"statusCode\": 201,\n  \"data\": {\n    \"_id\": \"67b63b95c6a46e7f5a8bd231\",\n    \"title\": \"My First Blog\",\n    \"content\": \"This is the content of my blog.\",\n    \"author\": \"67b5cec5b7c756f9eb43ef66\"\n  }\n}\n```\n\n### 4. Get All Blogs (Public API)\n\n- **Endpoint:** `/api/blogs`\n- **Method:** `GET`\n- Supports query parameters for **search**, **sorting**, and **filtering**\n\nExample Request:\n\n```\n/api/blogs?search=technology\u0026sortBy=createdAt\u0026sortOrder=desc\u0026filter=authorId\n\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"message\": \"Blogs fetched successfully\",\n  \"statusCode\": 200,\n  \"data\": [\n    {\n      \"_id\": \"67b63b95c6a46e7f5a8bd231\",\n      \"title\": \"My First Blog\",\n      \"content\": \"This is the content of my blog.\",\n      \"author\": {\n        \"_id\": \"67b5cec5b7c756f9eb43ef66\",\n        \"name\": \"Porimol Raj\",\n        \"email\": \"porimol@gmail.com\",\n        \"role\": \"user\",\n        \"isBlocked\": false,\n        \"createdAt\": \"2025-02-19T12:29:57.264Z\",\n        \"updatedAt\": \"2025-02-19T12:29:57.264Z\"\n      },\n      \"isPublished\": true,\n      \"createdAt\": \"2025-02-19T20:14:13.138Z\",\n      \"updatedAt\": \"2025-02-19T20:14:13.138Z\"\n    },\n    {},\n    {}\n  ]\n}\n```\n\n### 5. Update Blog\n\n- **Endpoint:** `api/blogs/:id`\n- **Method:** `PATCH`\n- **Requires Authentication** (`Authorization: Bearer \u003ctoken\u003e`)\n\n**Request Body:**\n\n```json\n{\n  \"title\": \"Updated Blog Title Here\",\n  \"content\": \"Updated content Here\"\n}\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"message\": \"Blog updated successfully\",\n  \"statusCode\": 200,\n  \"data\": {\n    \"_id\": \"67b5d9d75a13d47027f01d2b\",\n    \"title\": \"Updated Blog Title Here\",\n    \"content\": \"Updated content Here\",\n    \"author\": {\n      \"_id\": \"67b5cec5b7c756f9eb43ef66\",\n      \"name\": \"Porimol Raj\",\n      \"email\": \"porimol@gmail.com\",\n      \"role\": \"user\",\n      \"isBlocked\": false,\n      \"createdAt\": \"2025-02-19T12:29:57.264Z\",\n      \"updatedAt\": \"2025-02-19T12:29:57.264Z\"\n    }\n  }\n}\n```\n\n### 6. Delete Blog\n\n- **Endpoint:** `/api/blogs/:id`\n- **Method:** `DELETE`\n- **Requires Authentication** (`Authorization: Bearer \u003ctoken\u003e`)\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"message\": \"Blog deleted successfully\",\n  \"statusCode\": 200\n}\n```\n\n### 7. Admin Actions - Block User\n\n- **Endpoint:** `/api/admin/users/:userId/block`\n- **Method:** `PATCH`\n- **Requires Admin Role**\n- **Requires Authentication** (`Authorization: Bearer \u003ctoken\u003e`)\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"message\": \"User blocked successfully\",\n  \"statusCode\": 200\n}\n```\n\n### 8. Admin Actions- Delete Blogs\n\n- **Endpoint:** `/api/admin/blogs/:id`\n- **Method:** `DELETE`\n- **Requires Admin Role**\n- **Requires Authentication** (`Authorization: Bearer \u003ctoken\u003e`)\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"message\": \"Blog deleted successfully\",\n  \"statusCode\": 200\n}\n```\n\n---\n\n## Project Overview Video\n\n\u003ca href='https://drive.google.com/file/d/1pcnRsgpy2-w2cPKWfWU6PXf0QXHhkSZ8/view?usp=drive_link' target=_blank\u003e\n    \u003cimg width='350px' src=\"./readmeImg/watch-video-button-01.png\" /\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloper-shourav%2Fdev-story-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeveloper-shourav%2Fdev-story-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloper-shourav%2Fdev-story-backend/lists"}