Преглед изворни кода

Improve namings for ingredient suggestions

Tatiana Inama пре 7 година
родитељ
комит
27e0135c3d
2 измењених фајлова са 8 додато и 8 уклоњено
  1. 5 5
      ktchn/src/recipes/controller.ts
  2. 3 3
      ktchn/src/recipes/model.ts

+ 5 - 5
ktchn/src/recipes/controller.ts

@@ -1,5 +1,5 @@
 import { Request, Response, NextFunction } from 'express'
-import { Recipe, IIngredient, IIngredientHelper } from './model';
+import { Recipe, IIngredient, IngredientSuggestion } from './model';
 import { IMongoService } from '../mongo';
 import { FilterQuery } from 'mongodb';
 import Scrape from './scrape/index';
@@ -14,11 +14,11 @@ function validRecipe(data: any): Promise<Recipe> {
 
 type Controller<T> = (db: IMongoService) => (req: Request, res: Response, next: NextFunction) => Promise<T>;
 
-const getPossibleValues = (db: IMongoService) => async function(ingredient: IIngredient): Promise<IIngredientHelper> {
-  const possibleValues = await db.find<Ingredient>({$text: {$search: ingredient.name}}, { score: { $meta: "textScore" } });
+const getSuggestions = (db: IMongoService) => async function(ingredient: IIngredient): Promise<IngredientSuggestion> {
+  const suggestions = await db.find<Ingredient>({$text: {$search: ingredient.name}}, { score: { $meta: "textScore" } });
   return {
     ...ingredient,
-    possibleValues: possibleValues,
+    suggestions,
   }
 }
 
@@ -26,7 +26,7 @@ const scrape: Controller<void|ScrapedRecipe> = (db) => (req: any, res, next) =>
   return Scrape(req.body.url)
     .then(async scrapedRecipe => {
       const recipeIngredients = await Promise.all(scrapedRecipe.ingredients.map(async subGroup => {
-        const subgroupIngredients = await Promise.all(subGroup.ingredients.map(getPossibleValues(db)));
+        const subgroupIngredients = await Promise.all(subGroup.ingredients.map(getSuggestions(db)));
         return ({
           name: subGroup.name,
           ingredients: subgroupIngredients

+ 3 - 3
ktchn/src/recipes/model.ts

@@ -15,8 +15,8 @@ export interface IIngredient {
   _original?: string;
 }
 
-export interface IIngredientHelper extends IIngredient { 
-  possibleValues: Ingredient[],
+export interface IngredientSuggestion extends IIngredient { 
+  suggestions: Ingredient[],
 }
 
 export interface ISubRecipe {
@@ -65,7 +65,7 @@ export interface ScrapedRecipe {
   name: string;
   ingredients: {
     name: string,
-    ingredients: IIngredientHelper[]
+    ingredients: IngredientSuggestion[]
   }[];
   details?: RecipeDetails;
   instructions?: string[];