Commit 10e7c204 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira

Merge branch '15-adicionar-middleware-para-incluir-dbhandler' into 'develop'

Resolve "Adicionar middleware para incluir dbHandler"

Closes #15

See merge request !9
parents 13457ba9 b6d3913c
Pipeline #19972 passed with stages
in 57 seconds
......@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 0.0.7 - 10-04-2019
### Changed
- main.ts to include dbHandler Middleware and remove dummie class
### Added
- Create dbHandler Middleware to be abble to access by routes #15 (Horstmann)
## 0.0.6 - 01-04-2019
### Changed
- Input class to match with database model (Add id and description) (Horstmann)
......
{
"name": "form-creator-api",
"version": "0.0.6",
"version": "0.0.7",
"description": "RESTful API used to manage and answer forms.",
"main": "index.js",
"scripts": {
......
......@@ -20,7 +20,7 @@
*/
import * as express from "express";
import { Collection } from "../core/collection";
import { DbHandler } from "../utils/dbHandler";
/**
* Extension of Express requests that suports the addition
......@@ -31,8 +31,8 @@ import { Collection } from "../core/collection";
* return a error the extension must be made.
*/
export interface Request extends express.Request {
/** A collection object. Simulate a database. */
collection: Collection;
/** A Database handler instace */
db: DbHandler;
}
/**
......
This diff is collapsed.
......@@ -19,18 +19,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Collection } from "../../core/collection";
import { configs } from "../../utils/config";
import { DbHandler } from "../../utils/dbHandler";
import { Middleware } from "../apiTypes";
/**
* Creates a engine and middleware that
* inserts the collection into the request objects.
* inserts the handler into the request objects.
*/
export function CollectionMw (): Middleware {
const collection: Collection = new Collection();
return function collectionMiddleware(req, res, next) {
req.collection = collection;
export function DbHandlerMw (): Middleware {
const db: DbHandler = new DbHandler(configs.poolconfig);
return function dbHandlerMiddleware(req, res, next) {
req.db = db;
next();
};
}
......@@ -36,7 +36,7 @@ const app = module.exports = express();
const port = process.env.PORT;
// Include middlewares
import { CollectionMw } from "./api/middlewares/collection";
import { DbHandlerMw } from "./api/middlewares/dbHandler";
// Include controllers
import { ItemCtrl } from "./api/controllers/item";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment