Skip to content

ErtanOzdemir/jsad-backend

 
 

Repository files navigation

Screenshot 2023-08-23 at 13 30 26

Introduction

Welcome to the backend repository of JSArticles.dev project, a platform designed to deliver weekly newsletters to users. This project aims to provide a seamless and efficient way to manage and distribute newsletters.

Technologies

             

🚀 Features

  • Newsletter Management: The backend enables newsletter creators to compose, schedule, and manage newsletters effortlessly.
  • Subscriber Management: Users can subscribe to newsletter, while admins can access subscriber lists.
  • Employee Management: Employees can create newsletters and edit these newsletters based on their roles.
  • Authentication and Security: Robust authentication mechanisms ensure data privacy and secure access for both creators and subscribers.
  • API-driven Design: Our backend follows a RESTful API design, facilitating integration with frontend applications and third-party services.

🏃‍♀️ Getting Started

Prerequisites

Before you begin, ensure you have met the following requirements:

Installation and Setup

1- Clone the Repository:

git clone https://github.com/jsarticles-dev/jsad-backend
cd jsad-backend

2- Install Dependencies:

npm install

3- Configure Environment Variables:
Create a .env.development file in the root directory and provide the required environment variables. Refer to the .env.example file for a list of variables you need to set.

4- Start the Server:

npm run start:dev

4- Access the API:
The API will be available at http://localhost:3000 by default. You can use tools like Postman to interact with the API endpoints.

5- Testing:
Run tests to ensure everything is working as expected:

npm run test

6- Linting
To ensure code quality and consistency, you can run the linting script:

npm run lint

7- Building Compile TypeScript files:

npm run build

📚 API Documentation

User Routes

Endpoint Method Authentication Description
/users/:id GET Requires employee auth and specific roles Fetches user details based on the provided ID
/users GET Requires employee auth and specific roles Retrieves a list of all users
/users POST Description: Adds a new user.
Request Body:
json { "email": "user@example.com" }
/users/:id DELETE Description: Deletes the user with the provided ID

Newsletter Routes

Endpoint Method Authentication Description
/newsletters GET Retrieves a list of all newsletters
/newsletters/:id GET Fetches newsletter details based on the provided ID
/newsletters POST Requires employee auth Description: Creates a new newsletter.
Request Body:
json { "content": "Newsletter content", "dateOfDispatch": "2023-08-31", "header": "Newsletter header" }
/newsletters/:id PUT Requires employee auth Description: Updates the newsletter with the provided ID.
Request Body:
At least one of the following fields is required: isSent, header, content, dateOfDispatch.
json { "header": "Updated header", "content": "Updated content", "dateOfDispatch": "2023-09-01" }
/newsletters/:id DELETE Requires employee auth Description: Deletes the newsletter with the provided ID

Employee Routes

Endpoint Method Authentication Description
/employees GET Requires employee auth and specific roles Retrieves a list of all employees
/employees/:id GET Requires employee auth and specific roles Fetches employee details based on the provided ID
/employees/login POST Description: Allows an employee to log in.
Request Body:
json { "email": "user@example.com" }
/employees/register POST Requires employee auth and specific roles Description: Registers a new employee.
Request Body:
json { "name": "John Doe", "email": "john@example.com", "password": "secretpassword", "role": "EDITOR" }
/employees/:id PATCH Requires employee auth and specific roles Description: Updates employee details based on the provided ID.
Request Body:
json { "name": "Updated Name", "email": "updated@example.com", "password": "updatedpassword", "role": "ADMIN" }
/employees/:id DELETE Requires employee auth and specific roles Description: Deletes the employee with the provided ID

Authentication Routes

Endpoint Method Authentication Description
/auth/isValid GET Checks if a token is valid for auth

✅ Testing

Run Tests: Use the following command to execute the tests:

npm test

This command will trigger Jest to run all the test files in the tests directory. You'll see the test results and any failures in the terminal.

The testing setup includes:

Unit tests for individual functions or components. Integration tests using Supertest to test API endpoint and its response.

License

MIT License

This project is licensed under the MIT License - see the LICENSE file for details.

About

jsarticles.dev backend.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.2%
  • Other 0.8%