<!-- PROJECT LOGO -->
<br />
<p align="center">
  <a href="https://github.com/tiendamiaOfficial/backend-module-boilerplate">
    <img src="https://avatars.githubusercontent.com/u/86080112?s…00&u=3094e41145b256957cb170a4e167d82a60496641&v=4" alt="Logo" width="80" height="80">
  </a>

<h3 align="center">
product-categorization-engine-module
</h3>

  <p align="center">
    Module responsable for product categorization
    <br />
    <a href="https://github.com/tiendamiaOfficial/product-categorization-engine-module"><strong>Explore the docs
»</strong></a>
    <br />
    <br />
  </p></p>



<!-- TABLE OF CONTENTS -->
<details open="open">
  <summary><h2 style="display: inline-block">Table of Contents</h2></summary>
  <ol>
    <li>
      <a href="#about-the-project">About The Project</a>
      <ul>
        <li><a href="#built-with">Built With</a></li>
        <li><a href="#bd-diagram">BD Diagram</a></li>
      </ul>
    </li>
    <li>
      <a href="#getting-started">Getting Started</a>
      <ul>
        <li><a href="#prerequisites">Prerequisites</a></li>
        <li><a href="#installation">Installation</a></li>
      </ul>
    </li>
    <li>
        <a href="#usage">Usage</a>
        <ul>
            <li><a href="#how-to-use-logs-with-winston">Logs usage</a></li>
            <li><a href="#how-to-set-connection-or-configurations-params">Configurations</a></li>
            <li><a href="#how-to-connect-to-database">Connect to database</a></li>
            <li><a href="#how-to-use-dependency-injection">Dependency Injection</a></li>
      </ul>
</li>
    <li><a href="#contributing">Contributing</a></li>
    <li><a href="#publish">Publish module on npmjs.com</a></li>
  </ol>
</details>



<!-- ABOUT THE PROJECT -->
## About The Project
**Module for backend of categorization tools, this module has tu be installed in [backend-backoffice](https://github.com/tiendamiaOfficial/backend-backoffice)**


### Built With

* [NodeJs](https://nodejs.org/en/docs/)
* [npm](https://www.npmjs.com/)
* [TypeScript](https://www.typescriptlang.org/)
* [Sequelize ORM](https://sequelize.org/master/manual/getting-started.html)
* [esLint](https://eslint.org/)
* [dotenv](https://www.npmjs.com/package/dotenv)
* [jest](https://jestjs.io/)
* [winston](https://www.npmjs.com/package/winston)
* [inversify](https://inversify.io/)

### BD Diagram
<img src="https://github.com/tiendamiaOfficial/product-categorization-engine-module/blob/master/doc/bd_diargam.png"
alt="BD" width="80" height="80">

<!-- GETTING STARTED -->
## Getting Started

To get a local copy up and running follow these simple steps.

### Prerequisites

This is an example of how to list things you need to use the software and how to install them.
* npm
  ```sh
  npm install npm@latest -g
  ```

### Installation

1. Clone the repo
   ```sh
   git clone https://github.com/tiendamiaOfficial/backend-categorization-module.git
   ```
2. Install NPM packages
   ```sh
   npm install
   ```


<!-- USAGE EXAMPLES -->
## Usage

### How to use logs with winston
   ```typescript
    logger.error(err);
    logger.info(err);
   ```

##
### How to set connection or configurations params
all configurations should be set in `.env` file , example
   ```
    # Put lots of randomness in these
    SESSION_SECRET=ashdfjhasdlkjfhalksdjhflak
   ```
the project has the module `dotenv-flow` it allow to have a `.env` file for each environment
overriding `.env` property in each child

```
 .env.local
 .env.test
 .env.staging
 .env.production
```

you can execute node comand using the enviroment and each enviroment has a `.env` file
example `"NODE_ENV=test jest --forceExit --coverage --verbose"`

##
### How to connect to database

Connection to database are handler in a single service `dbConnection`, that service
has methods like: `connect()` and `close()`.

The database connection params is configured in `.env` file

##
### How to use dependency injection

For consuming service injected in dependency injection.
```
const VAR_NAME = container.get<NAME_OF_SERVICE>(TYPES.NAME_OF_SERVICE);
```

For inject service on the dependency injection system

Add on `/lib/ContainerInjection.ts` the next code.

```
container.bind<NAME_OF_SERVICE>(TYPES.DbConnection).to(NAME_OF_SERVICE);
```
and add on `/lib/Types.ts`

```
const TYPES = {
    NAME_OF_SERVICE: Symbol.for('NAME_OF_SERVICE'),
};
```

##
<!-- CONTRIBUTING -->
### Contributing

1. Clone the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

##
## Publish module
### Publish

1 - Open the terminal and run the next command `npm login` and login with `tiendamiadev` credentials.

2 - Publish package `npm publish --access restricted`.


##
