# Sanazoo

[GitHub repo](https://github.com/Nouuu/SanaZoo-API)

![package.json version](https://img.shields.io/github/package-json/v/SwannHERRERA/SanaZoo-API)![express
version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/express)![sequelize
version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/sequelize)![typescript
version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/dev/typescript)

SanaZoo is a very popular zoo !

First created in C with XML files, it is now developed with nodejs and swagger, for your eyes only

## Our project

In this school project, we have to realize a complete API to manage a zoo, using Express and Sequelize as a base.

This project has been tested and integrated both on heroku, but also thanks to docker whose image is detailed below

Project Syllabus : [Syllabus.pdf](https://wiki2.nospy.fr/attachments/1)

### Gantt chart

This project was carried out using a gantt chart :

[![image-20210424163444370.png](https://wiki2.nospy.fr/uploads/images/gallery/2022-05/scaled-1680-/image-20210424163444370.png)](https://wiki2.nospy.fr/uploads/images/gallery/2022-05/image-20210424163444370.png)

### Data model used for DB

Here is our DB model used for this project :

[![Planode-Zoo.png](https://wiki2.nospy.fr/uploads/images/gallery/2022-05/scaled-1680-/planode-zoo.png)](https://wiki2.nospy.fr/uploads/images/gallery/2022-05/planode-zoo.png)

### Contributions

|                                                  |                                                                                                       |
|--------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| [Noé LARRIEU-LACOSTE](https://github.com/Nouuu)  | [![followers](https://img.shields.io/github/followers/nouuu)]((https://github.com/Nouuu))             |
| [Swann HERRERA](https://github.com/SwannHERRERA) | [![followers](https://img.shields.io/github/followers/SwannHERRERA)](https://github.com/SwannHERRERA) |
| [Clément BOSSARD](https://github.com/Huriumari)  | [![followers](https://img.shields.io/github/followers/Huriumari)](https://github.com/Huriumari)       |

## Information about code

### Docker integration

Our docker image is built in 2 step :

- First we build all the project with dev dependencies
- Then we only keep production dependencies with compiled project

This reduce drastictly the size of the image

```dockerfile
## Stage 1 building the code
FROM node:lts-alpine as builder
WORKDIR /usr/app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

## Stage 2 final stage with builded code
FROM node:lts-alpine
WORKDIR /usr/app
COPY package*.json ./
RUN npm ci --production

COPY --from=builder /usr/app/dist ./dist

ENV PORT=3000 \
    DB_PORT=3306 \
    DB_DRIVER='mysql' \
    DB_HOST='localhost' \
    DB_NAME='zoo' \
    DB_USER='root' \
    DB_PASSWORD=''

CMD node dist/src/index.js
```

#### Env

| Environment variable | Default   | Description                             |
|----------------------|-----------|-----------------------------------------|
| PORT                 | 3000      | Express listen port                     |
| DB_DRIVER            | mysql     | Driver for sql connection for sequelize |
| DB_HOST              | localhost | Host domain / IP for DB                 |
| DB_NAME              | zoo       | DB Schema name                          |
| DB_USER              | zoo       | DB user                                 |
| DB_PASSWORD          | `empty`   | DB password                             |

### Main dependencies

| Dependency         | Version                                                                                                                      | Description                                                                |
|--------------------|------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------|
| Express            | ![express version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/express)           | Web API Framework                                                          |
| Date FNS           | ![date-fns version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/date-fns)         | Useful librairies to manipulates dates                                     |
| Dotenv             | ![date fns version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/dotenv)           | Used to load `.env` file                                                   |
| Argon2             | ![argon2 version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/argon2)             | Used to encrupt users password                                             |
| Mysql2             | ![mysql version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/mysql2)              | DB driver                                                                  |
| Sequelize          | ![sequelize version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/sequelize)       | Orm librairies to bind class to DB entities                                |
| Swagger-jsdoc      | ![version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/swagger-jsdoc)             | Used to implements swagger page                                            |
| Swagger-ui-express | ![version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/swagger-ui-express)        | Used to implements swagger page                                            |
| Yup                | ![yup version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/yup)                   | Form validation library used to validate data in post body of our requests |
| Typescript         | ![typescript version](https://img.shields.io/github/package-json/dependency-version/SwannHERRERA/SanaZoo-API/dev/typescript) | Very useful to use types in JS based framework                             |

## API Endpoints

### Postman Environment

You can check our endpoints with postman directly on this URL:
[https://documenter.getpostman.com/view/11568150/TzJvdwNA](https://documenter.getpostman.com/view/11568150/TzJvdwNA)

**API Description :**

* [Affluence](#affluence)
    + [Daily](#1-daily)
    + [Daily by enclosure](#2-daily-by-enclosure)
    + [Live enclosure affluence](#3-live-enclosure-affluence)
    + [Monthly](#4-monthly)
    + [Monthly by enclosure](#5-monthly-by-enclosure)
    + [Total](#6-total)
    + [Total by enclosure](#7-total-by-enclosure)
    + [Weekly](#8-weekly)
    + [Weekly by enclosure](#9-weekly-by-enclosure)
    + [1Yearly](#10-yearly)
    + [1Yearly by enclosure](#11-yearly-by-enclosure)
* [Animal](#animal)
    + [Create](#1-create)
    + [Delete](#2-delete)
    + [Get all](#3-get-all)
    + [Get by id](#4-get-by-id)
    + [Move Enclosure](#5-move-enclosure)
    + [Update](#6-update)
* [Animal Health Book](#animal-health-book)
    + [Create entry](#1-create-entry)
    + [Delete](#2-delete-1)
    + [Get All](#3-get-all)
    + [Get All By Animal](#4-get-all-by-animal)
    + [Get One](#5-get-one)
    + [Update](#6-update-1)
* [Enclosure](#enclosure)
    + [Add One](#1-add-one)
    + [Delete One](#2-delete-one)
    + [Edit One](#3-edit-one)
    + [Get All](#4-get-all)
    + [Get All Animals In Enclosure](#5-get-all-animals-in-enclosure)
    + [Get All By Type](#6-get-all-by-type)
    + [Get One](#7-get-one)
* [Enclosure Images](#enclosure-images)
    + [Add](#1-add)
    + [Delete One](#2-delete-one-1)
    + [Edit One](#3-edit-one-1)
    + [Gell All From Enclosure](#4-gell-all-from-enclosure)
    + [Get All](#5-get-all)
    + [Get One](#6-get-one)
* [Enclosure Service-book](#enclosure-service-book)
    + [Create service-book](#1-create-service-book)
    + [Delete service-book](#2-delete-service-book)
    + [Edit service-book](#3-edit-service-book)
    + [Gell All From Employee](#4-gell-all-from-employee)
    + [Get All](#5-get-all-1)
    + [Get All From Enclosure](#6-get-all-from-enclosure)
    + [Get One](#7-get-one-1)
* [Enclosure Type](#enclosure-type)
    + [Create](#1-create-1)
    + [Delete](#2-delete-2)
    + [Get All](#3-get-all-1)
    + [Get One](#4-get-one)
    + [Update](#5-update)
* [Entry](#entry)
    + [Add entry](#1-add-entry)
    + [Get all](#2-get-all)
    + [Get by enclosure](#3-get-by-enclosure)
    + [Get by pass](#4-get-by-pass)
    + [Get by user](#5-get-by-user)
    + [Remove entry](#6-remove-entry)
* [Maintenance](#maintenance)
    + [Get All by State](#1-get-all-by-state)
    + [Get Best Month](#2-get-best-month)
    + [Update Maintenance State](#3-update-maintenance-state)
* [Pass](#pass)
    + [Add enclosure access](#1-add-enclosure-access)
    + [Create](#2-create)
    + [Delete pass](#3-delete-pass)
    + [Get all](#4-get-all)
    + [Get all by user id](#5-get-all-by-user-id)
    + [Get by id](#6-get-by-id)
    + [Remove enclosure access](#7-remove-enclosure-access)
    + [Update pass](#8-update-pass)
* [Pass Night](#pass-night)
    + [Add availability](#1-add-availability)
    + [Delete passnight](#2-delete-passnight)
    + [Get all](#3-get-all-1)
    + [Get all valid](#4-get-all-valid)
    + [Update passnight](#5-update--passnight)
* [Pass Type](#pass-type)
    + [Add pass to pass type](#1-add-pass-to-pass-type)
    + [Create](#2-create-1)
    + [Delete](#3-delete)
    + [Get all](#4-get-all-1)
    + [Get by id](#5-get-by-id)
    + [Update](#6-update-2)
* [Planning](#planning)
    + [Add](#1-add-1)
    + [Delete](#2-delete-3)
    + [Get All](#3-get-all-2)
    + [Get Calendar](#4-get-calendar)
    + [Get One](#5-get-one-1)
    + [Get Open Date](#6-get-open-date)
    + [Update](#7-update)
* [Specie](#specie)
    + [Create](#1-create-2)
    + [Delete](#2-delete-4)
    + [Get All](#3-get-all-3)
    + [Get By ID](#4-get-by-id)
    + [Update](#5-update-1)
* [Statistics](#statistics)
    + [Count all pass](#1-count-all-pass)
    + [Count all pass by types](#2-count-all-pass-by-types)
    + [Count animal](#3-count-animal)
    + [Count animal by enclosure](#4-count-animal-by-enclosure)
    + [Count enclosure](#5-count-enclosure)
    + [Count expired pass](#6-count-expired-pass)
    + [Count user](#7-count-user)
    + [Count valid pass](#8-count-valid-pass)
    + [Count valid pass by types](#9-count-valid-pass-by-types)
* [User](#user)
    + [Change Password](#1-change-password)
    + [Create](#2-create-2)
    + [Delete](#3-delete-1)
    + [Force Delete](#4-force-delete)
    + [Get All](#5-get-all-2)
    + [Get By ID](#6-get-by-id)
    + [Login](#7-login)
    + [Logout](#8-logout)
    + [ME](#9-me)
    + [Register](#10-register)
    + [Restaure User](#11-restaure-user)
    + [Update by admin](#12-update-by-admin)
    + [Update client only by employee](#13-update-client-only-by-employee)
* [User Role](#user-role)
    + [Affect User](#1-affect-user)
    + [Create](#2-create-3)
    + [Delete](#3-delete-2)
    + [Get All](#4-get-all-1)
    + [Get by ID](#5-get-by-id)
    + [Update](#6-update-3)
* [Swagger](#swagger)

---

### Swagger

This project contain a complete swagger test environment to use API, you can access it
on `https://domain.example/swagger`

It look FABULOUS :

[![image-20210424170307083.png](https://wiki2.nospy.fr/uploads/images/gallery/2022-05/scaled-1680-/image-20210424170307083.png)](https://wiki2.nospy.fr/uploads/images/gallery/2022-05/image-20210424170307083.png)