|
@@ -1,7 +1,7 @@
|
|
|
import { Request, Response, Router, NextFunction } from "express";
|
|
import { Request, Response, Router, NextFunction } from "express";
|
|
|
import Scrape from "./scrape";
|
|
import Scrape from "./scrape";
|
|
|
import { Recipe } from './model';
|
|
import { Recipe } from './model';
|
|
|
-import { save, get, getById, getAll, getByIngredients } from './controller';
|
|
|
|
|
|
|
+import { save, get, getById, getAll, getByIngredients, scrape } from './controller';
|
|
|
import MongoClient from 'mongodb';
|
|
import MongoClient from 'mongodb';
|
|
|
import { mongoService, IMongoService } from '../mongo';
|
|
import { mongoService, IMongoService } from '../mongo';
|
|
|
import piddleware from '../promise-all-middleware';
|
|
import piddleware from '../promise-all-middleware';
|
|
@@ -9,10 +9,12 @@ import piddleware from '../promise-all-middleware';
|
|
|
class RecipeRoutes {
|
|
class RecipeRoutes {
|
|
|
public router: Router;
|
|
public router: Router;
|
|
|
private RecipeDB: IMongoService;
|
|
private RecipeDB: IMongoService;
|
|
|
|
|
+ private IngredientDB: IMongoService;
|
|
|
|
|
|
|
|
public constructor(db: MongoClient.Db) {
|
|
public constructor(db: MongoClient.Db) {
|
|
|
this.router = Router();
|
|
this.router = Router();
|
|
|
this.RecipeDB = mongoService(db)('recipes');
|
|
this.RecipeDB = mongoService(db)('recipes');
|
|
|
|
|
+ this.IngredientDB = mongoService(db)('ingredients');
|
|
|
this.init();
|
|
this.init();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -23,16 +25,7 @@ class RecipeRoutes {
|
|
|
this.router.get("/id/:id", piddleware([getById(this.RecipeDB)]));
|
|
this.router.get("/id/:id", piddleware([getById(this.RecipeDB)]));
|
|
|
|
|
|
|
|
this.router.post("/", piddleware([save(this.RecipeDB)]));
|
|
this.router.post("/", piddleware([save(this.RecipeDB)]));
|
|
|
- this.router.post("/scrape", (req, res, next) => {
|
|
|
|
|
- return Scrape(req.body.url).then((x)=>{
|
|
|
|
|
- res.json(x)
|
|
|
|
|
- }).catch((error: Error) => res.status(400).send(
|
|
|
|
|
- {
|
|
|
|
|
- name: error.name,
|
|
|
|
|
- message: error.message,
|
|
|
|
|
- }
|
|
|
|
|
- ));
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ this.router.post("/scrape", piddleware([scrape(this.IngredientDB)]));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private logData(req:Request, res:Response, next: NextFunction): void {
|
|
private logData(req:Request, res:Response, next: NextFunction): void {
|