# Terminology Management API

## Overview

This project is a Node.js application that provides a RESTful Terminology Management API. It includes Create and Get operations for managing terminologies, such as creating, retrieving terminologies. The API is documented using Swagger for easy exploration and is thoroughly tested with Jest.

## Features

- **Create Terminology**: Add a new terminology to the database.
- **Get Terminologies**: Retrieve a list of terminologies with optional pagination.

## Technologies

- **Node.js**: JavaScript runtime for server-side programming.
- **Express**: Web framework for building the API.
- **Swagger**: API documentation tool.
- **Jest**: Testing framework for unit and integration tests.
- **Babel**: JavaScript compiler to use ES6+ syntax.
- **Supertest**: HTTP assertions for testing API endpoints.
- **Prisma**: ORM for database management and querying.

## Prerequisites

Before running this project, ensure you have the following installed:

- [Node.js](https://nodejs.org/) (version 12.x or later)
- [npm](https://www.npmjs.com/) (comes with Node.js)
- [PostgreSQL](https://sbp.enterprisedb.com/getfile.jsp?fileid=1259129) (for database management)

## Installation

Follow these steps to set up the project locally:

1. **Clone the repository:**

   `git clone <repository-url>`

   `cd <repository-directory>`

2. **Install dependencies:**

   `npm install`

3. **Set up environment variables:**

   Create a `.env` file in the root directory and add the necessary environment variables. Example:

   `PORT=3000`

4. **Ensure PostgreSQL is running:**

   Download and install PostgreSQL from [this link](https://sbp.enterprisedb.com/getfile.jsp?fileid=1259129) if you haven't already. Make sure PostgreSQL is running and properly configured.

## Running the Application

To start the application, run:

`npm start`

The server will run on [http://localhost:3000](http://localhost:3000) by default. You can change the port by setting the `PORT` environment variable in the `.env` file.

## Version Update

There are three commands which automatically updates the version of the project in your package.json. Ensure that you keep a clean working directory, i.e., dont have any uncommited changes before using these commands. So once commit is done, update the version and then push the code onto git.

1. **patch**
  ```bash
   npm version patch
  ```
  This updates the version in this manner 1.0.0 -> 1.0.1
  

2. **minor**
  ```bash
   npm version minor
  ```
  This updates the version in this manner 1.0.0 -> 1.1.0

3. **major**
  ```bash
   npm version patch
  ```
  This updates the version in this manner 1.0.0 -> 2.0.0

## Change Log

To view all the changes made in the project till date, use the below mentioned command line in the terminal of the project.
  ```bash
   auto-changelog
  ```


## API Documentation

The API is documented using Swagger. Once the application is running, you can access the Swagger UI at:

[http://localhost:3000/api-docs](http://localhost:3000/api-docs)

## Running Tests

To run the test suite, use:

`npm test`

Jest will execute the test suite and provide feedback on the status of your tests.

## Prisma Commands

Prisma is used for database schema management and operations. Below are the key Prisma commands you will use in this project:

- **Initialize Prisma in your project:**

  `npx prisma init`

  This command sets up Prisma in your project by creating a `prisma` directory with the necessary configuration files.

- **Run migrations:**

  `npx prisma migrate dev --name <migration-name>`

  This command creates a new migration file based on the changes in your Prisma schema and applies it to the database.

- **Generate Prisma Client:**

  `npx prisma generate`

  This command generates the Prisma Client, which is a type-safe database client for interacting with your database.

- **Reset the database and apply all migrations:**

  `npx prisma migrate reset`

  This command resets the database by dropping all tables and reapplying all migrations. Use this with caution as it will delete all existing data.

- **View the database schema:**

  `npx prisma db pull`

  This command pulls the current database schema into your Prisma project, which can be useful for keeping the schema file up to date with the database.

- **Open Prisma Studio:**

  `npx prisma studio`

  This command opens Prisma Studio, a web-based GUI to view and edit the data in your database.

## Project Structure

- **src/controllers**: This directory contains the controller files, which are responsible for handling incoming API requests, processing them, and sending appropriate responses back to the client. Controllers act as the intermediaries between the client and the business logic.

- **src/routes**: This folder contains the routing files that define the endpoints of your API and map them to the corresponding controller methods. Each route file typically corresponds to a specific resource or group of related API endpoints.

- **src/middlewares**: This directory includes middleware functions that process requests before they reach the controllers. Middleware can be used for tasks such as authentication, logging, validation, and error handling.

- **src/services**: Contains service files that encapsulate business logic and interact with external APIs or internal modules. Services act as an abstraction layer between the controllers and other parts of the application, promoting reusability and separation of concerns.

- **src/repositories**: This folder holds the repository files responsible for interacting with the database. Repositories handle data persistence, retrieval, and querying, providing an abstraction layer over the database operations.

- **src/models**: This directory contains the schema definitions used for validating incoming API requests using [Joi](https://joi.dev/). Joi is a powerful validation library that helps ensure that the data sent by the client meets the required format and constraints before being processed by the application.

- **src/transformers**: Contains files that handle the transformation of data, such as converting request data into a format suitable for processing or formatting responses before sending them back to the client. Transformers help ensure consistent data structures throughout the application.

- **src/utils**: This directory contains utility functions and constants used across the application. These utilities are usually small, generic functions that can be reused in different parts of the codebase.

- **prisma**: Contains the Prisma files for database schema management, migrations, and data modeling. Prisma is an ORM (Object-Relational Mapping) tool that simplifies database interactions by providing a type-safe query builder and schema management features.

- **docs**: This folder contains the Swagger documentation files for the API. Swagger is used to generate interactive API documentation, making it easier for developers to understand and test the API.

- **test**: The test directory includes all the test files for the application. These tests ensure that the application behaves as expected and help prevent regressions. Typically, this includes unit tests, integration tests, and end-to-end tests.

## Configuration

- **Babel**: Used to transpile ES modules. Ensure Babel is configured properly with `babel.config.js`.
- **Jest**: Used for testing. Ensure Jest configuration is set up in `package.json` or `jest.config.js`.

## Contribution

Contributions are welcome! Feel free to submit issues or pull requests to help improve the project.

## License

This project is licensed under the MIT License.