Giter VIP home page Giter VIP logo

notification-backend's Introduction

Notification Service

This project provides a notification service built with Node.js, TypeScript, TypeORM, and Express. It allows you to send notifications and log them into a database. Additionally, it provides endpoints to retrieve the logs and check the service health.

Table of Contents

  1. Features
  2. Database Schema
  3. API Endpoints
  4. Getting Started
  5. Running the Project

Features

  • Send Notifications: Send notifications with different categories and types.
  • Log Notifications: Log all notifications into the database.
  • Retrieve Logs: Retrieve logs of all notifications, sorted from newest to oldest.
  • Health Check: Check the health status of the service.

Database Schema

The database consists of the following tables:

Users

Column Type Description
id INT Primary Key
name VARCHAR User's name
email VARCHAR User's email
phoneNumber VARCHAR User's phone number

Categories

Column Type Description
id INT Primary Key
name VARCHAR Category name

NotificationTypes

Column Type Description
id INT Primary Key
name VARCHAR Notification type name

UserSubscriptions

Column Type Description
id INT Primary Key
userId INT Foreign Key to Users
categoryId INT Foreign Key to Categories

UserNotificationChannels

Column Type Description
id INT Primary Key
userId INT Foreign Key to Users
notificationTypeId INT Foreign Key to NotificationTypes

NotificationLogs

Column Type Description
id INT Primary Key
userId INT Foreign Key to Users
categoryId INT Foreign Key to Categories
notificationTypeId INT Foreign Key to NotificationTypes
message TEXT Notification message
timestamp TIMESTAMP Time of notification

API Endpoints

POST /send-notifications

Send a notification and log it into the database.

Payload:

{
  "message": "Test Message",
  "category_id": "1",
  "notification_type_id": "1"
}

GET /notification-logs

Retrieve the logs of all notifications, sorted from newest to oldest.

Response:

[
  {
    "id": 2,
    "message": "Test Message",
    "timestamp": "2024-06-06T18:22:11.000Z",
    "user": null,
    "category": {
      "id": 1,
      "name": "Sports"
    },
    "notificationType": {
      "id": 1,
      "name": "SMS"
    }
  },
  {
    "id": 1,
    "message": "Test Message",
    "timestamp": "2024-06-06T18:17:26.000Z",
    "user": null,
    "category": {
      "id": 1,
      "name": "Sports"
    },
    "notificationType": {
      "id": 1,
      "name": "SMS"
    }
  }
]

GET /health-check

Check the health status of the service.

Response:

OK

Getting Started

Follow these steps to get the project up and running:

  1. Clone the repository:

    git clone <repository_url>
    cd <repository_directory>
  2. Install dependencies:

    npm install
  3. Create environment variables file: Create a .env file in the root directory with the following content:

    DB_HOST=localhost
    DB_PORT=5432
    DB_USERNAME=user
    DB_PASSWORD=password
    DB_DATABASE=notifications
    REDIS_URL=redis://localhost:6379

Running the Project

  1. Start Docker containers: Make sure Docker is installed and running on your machine, then start the services with Docker Compose.

    docker compose up
  2. Run the application:

    npm start

The application should now be running and accessible at http://localhost:3000.

Example Requests

Sending a Notification:

curl -X POST http://localhost:3000/api/send-notifications \
-H "Content-Type: application/json" \
-d '{
    "message": "Test Message",
    "category_id": "1",
    "notification_type_id": "1"
}'

Retrieving Notification Logs:

curl http://localhost:3000/api/notification-logs

Health Check:

curl http://localhost:3000/api/health-check

notification-backend's People

Contributors

vithorgoing2 avatar kledsonv avatar vithorluc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.