Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diegovictor/notifications-service
Micro-service to handle notifications. Project developed during the Node.js Ignite Lab 4.0
https://github.com/diegovictor/notifications-service
api docker javascript js kafka nestjs node nodejs notifications notifications-service sqlite ts typescript
Last synced: 2 months ago
JSON representation
Micro-service to handle notifications. Project developed during the Node.js Ignite Lab 4.0
- Host: GitHub
- URL: https://github.com/diegovictor/notifications-service
- Owner: DiegoVictor
- License: mit
- Created: 2022-12-19T22:39:59.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-09T06:52:19.000Z (3 months ago)
- Last Synced: 2024-11-09T07:32:50.702Z (3 months ago)
- Topics: api, docker, javascript, js, kafka, nestjs, node, nodejs, notifications, notifications-service, sqlite, ts, typescript
- Language: TypeScript
- Homepage:
- Size: 519 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Notifications Service
[](https://app.circleci.com/pipelines/github/DiegoVictor/notifications-service)

[](https://eslint.org/)
[](https://jestjs.io/)
[](https://codecov.io/gh/DiegoVictor/notifications-service)
[](https://raw.githubusercontent.com/DiegoVictor/notifications-service/main/LICENSE)
[](http://makeapullrequest.com)
[](https://insomnia.rest/run/?label=Notification%20Service&uri=https%3A%2F%2Fraw.githubusercontent.com%2FDiegoVictor%2Fnotifications-service%2Fmain%2FInsomnia_2022-12-15.json)Small microservice to handle notifications, it allows you to send and cancel notifications, mark as read/unread and get the recipient notifications list.
## Table of Contents
* [Installing](#installing)
* [Configuring](#configuring)
* [SQLite](#sqlite)
* [Kafka](#kafka)
* [Script](#script)
* [.env](#env)
* [Usage](#usage)
* [Routes](#routes)
* [Requests](#requests)
* [Running the tests](#running-the-tests)
* [Coverage report](#coverage-report)# Installing
Easy peasy lemon squeezy:
```
$ yarn
```
Or:
```
$ npm install
```
> Was installed and configured the [`eslint`](https://eslint.org/) and [`prettier`](https://prettier.io/) to keep the code clean and patterned.## Configuring
The application is using just one database: [SQLite](https://www.sqlite.org/index.html). For the fastest setup is recommended to use [docker-compose](https://docs.docker.com/compose/), you just need to up all services:
```
$ docker-compose up -d
```Or follow the instructions in [SQLite](#sqlite) and [Kafka](#kafka) sections.
### SQLite
It stores all the application's data. You just need to remember to run the migrations:
```
$ npx prisma migrate dev
```
> See more information on [Prisma Migrate](https://www.prisma.io/docs/concepts/components/prisma-migrate).### Kafka
Kafka is used to receive notifications through events:
```
$ docker-compose up -d zookeeper kafka
```
> Remember to run the application manually, see [Usage](#usage)#### Script
The repository is shipped with a script to help you to send random notifications to Kafka:
```
$ node scripts/send-message.js
```### .env
In this file you may configure the path to the SQLite database file and Kafka settings. Rename the `.env.example` in the root directory to `.env` then just update with your settings.|key|description|default
|---|---|---
|DATABASE_URL|Path to SQLite file.|`file:./dev.db`
|KAFKA_TOPIC|Name of the Kafka's topic.|`notifications.send-notification`
|KAFKA_BROKER|Kafka Broker URL.|`localhost:9092`# Usage
To start up the app run:
```
$ yarn start:dev
```
Or:
```
npm run start:dev
```## Routes
|route|HTTP Method|params|description
|:---|:---:|:---:|:---:
|`/notifications`|POST|Body with notification `content`, `category` and `recipientId`.|Create a new notification.
|`/notifications/recipient/:id`|GET|`:id` of the recipient.|Lists recipient notifications.
|`/notifications/recipient/:id/count`|GET|`:id` of the recipient.|Count recipient notifications.
|`/notifications/:id/cancel`|PATCH|`:id` of the notification.|Set notification as canceled.
|`/notifications/:id/read`|PATCH|`:id` of the notification.|Set notification as read.
|`/notifications/:id/unread`|PATCH|`:id` of the notification.|Set notification as unread.### Requests
* `POST /notifications`Request body:
```json
{
"content": "Lorem ipsum dolor sit amet",
"category": "example",
"recipientId": "69c9a4f1-adbb-44c7-97ca-eac8eee9f029"
}
```# Running the tests
[Jest](https://jestjs.io/) was the choice to test the app, to run:
```
$ yarn test
```
Or:
```
$ npm run test
```## Coverage report
You can see the coverage report inside `tests/coverage`. They are automatically created after the tests run.