-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (30 loc) · 846 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fetchMealById = require('./fetch-meal-by-id');
const fetchMeals = require('./fetch-meals');
const isTodaysMeal = require('./is-todays-meal');
let allMeals;
const getMeals = async companyId => {
const meals = allMeals || await fetchMeals(companyId);
return meals;
};
/**
* Get all meals.
* @param {string} companyId The company ID to query.
* @returns {array} The meals data.
*/
const all = async companyId => {
const meals = await getMeals(companyId);
return meals;
};
/**
* Get today's meal.
* @param {string} companyId The company ID to query.
* @returns {object} The meal data.
*/
const today = async companyId => {
const meals = await getMeals(companyId);
const {id} = meals.find(isTodaysMeal);
const meal = await fetchMealById(id);
return meal;
};
module.exports.all = all;
module.exports.today = today;