Skip to content

IS2-Class-Connect/classconnect-gateway-service

Repository files navigation

Table of Contents

Description

This repository has the implementation of the gateway server for the ClassConnect application. It redirects requests to the correct microservice and has some extra features such as push notification handling and email delivery. It uses NestJS and TypeScript.

The gateway will reroute the client to the specified service. For example GET /users/<uuid> will call the users-service with GET /users/<uuid> and return it's response to the user.

Use

Endpoints

Here are some curl examples for gateway specific endpoints.

To send a push notification use POST /notifications

curl -X 'POST' 'http://localhost:3000/notifications' \
  -H 'Authorization: Bearer {token}' \
  -H 'Content-Type: application/json' \
  -d '{
    "uuid":  "user id",
    "title": "notification title",
    "body":  "body of notification",
    "topic": "the topic of the notification"
  }'

To send a student enrollment mail use POST /email/student-enrollment.

curl -X 'POST' 'http://localhost:3000/email/student-enrollment' \
  -H 'Authorization: Bearer {token}' \
  -H 'Content-Type: application/json' \
  -d '{
    "uuid":         "user id",
    "toName":       "recipient name",
    "courseName":   "name of the enrolled course",
    "studentEmail": "the email of the recipient",
    "topic":        "enrollment"
  }'

To send an assistant assignment mail use POST /email/assistant-assignment.

curl -X 'POST' 'http://localhost:3000/email/assistant-assignment' \
  -H 'Authorization: Bearer {token}' \
  -H 'Content-Type: application/json' \
  -d '{
    "uuid":          "user id",
    "toName":        "recipient name",
    "professorName": "name of the professor in charge of the course",
    "courseName":    "the name of the course",
    "studentEmail":  "the email of the recipient",
    "topic":         "assistant-assignment"
  }'

To send a new rules and policies mail use POST /email/rules.

curl -X 'POST' 'http://localhost:3000/email/rules' \
  -H 'Authorization: Bearer {token}' \
  -H 'Content-Type: application/json' \
  -d '{
    "rules": [
      {
        "title": "the title of the rule",
        "description": "a description of this rule",
        "effective_date": "the date which the rule becomes relevant",
        "applicable_conditions": [
          "cond1",
          "cond2"
        ]
      }
    ]
  }'

To talk to the gateway through the backoffice use the path /admin-backend/*. For example this retrieves all the users.

curl 'http://localhost:3000/users' \
  -H 'Authorization: Bearer {token}'

To get a user without passing it's id use GET /users/me.

curl 'http://localhost:3000/users/me' \
  -H 'Authorization: Bearer {token}'

To patch a user without passing it's id use PATCH /users/me.

curl -X 'PATCH' 'http://localhost:3000/users/me' \
  -H 'Authorization: Bearer {token}' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "new name",
    "email": "new email",
    "description": "new description"
  }'

Technologies

  • NestJS: A progressive Node.js framework for building efficient and scalable server-side applications.
  • TypeScript: A strongly typed programming language that builds on JavaScript.
  • Package-Layered Architecture: A modular architecture pattern for better scalability and maintainability.

Project Setup

Prerequisites

Ensure you have the following installed:

  • Node.js (v16 or higher)
  • npm (v8 or higher)

Installation

Clone the repository and install dependencies:

$ git clone <repository-url> gateway
$ cd gateway
$ npm install

Running the Project

Development Mode

$ npm run start

Watch Mode

$ npm run start:dev

Production Mode

$ npm run start:prod

Testing

This project uses Jest for unit testing. To run tests:

$ npm run test

To run tests with coverage:

$ npm run test:cov

Tests will automatically run on every push or pull request to main via GitHub Actions.

Project Structure

.github/
└── workflows/
    └── ci.yml
src/
├── auth/
├── config/
├── controllers/
├── services/
├── firebase/
└── main.ts
test/

License

This project is MIT licensed.

Code Style

We use Prettier and ESLint to maintain consistent code formatting and quality. Use the following commands:

  • To check and fix lint issues:
$ npm run lint
  • To format files using Prettier:
$ npm run format
  • To check formatting without making changes:
$ npm run format:check

Codecov

codecov

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages