Return dailyCalories when getting meals
This commit is contained in:
parent
9a4f1038ff
commit
7744898c09
5
TODO.md
5
TODO.md
@ -1,5 +0,0 @@
|
||||
[ ] formula
|
||||
Women: BMR = 655 + (9.6 x weight in kg) + (1.8 x height in cm) - (4.7 x age in years)
|
||||
Men: BMR = 66 + (13.7 x weight in kg) + (5 x height in cm) - (6.8 x age in years)
|
||||
* activity
|
||||
+- 100 kcal
|
@ -7,6 +7,7 @@ dotenv.config({ path: path.join(__dirname, '../../.env') });
|
||||
const envVarsSchema = Joi.object()
|
||||
.keys({
|
||||
NODE_ENV: Joi.string().valid('production', 'development', 'test').required(),
|
||||
HOSTNAME: Joi.string().default('0.0.0.0'),
|
||||
PORT: Joi.number().default(3000),
|
||||
MONGODB_URL: Joi.string().required().description('Mongo DB url'),
|
||||
JWT_SECRET: Joi.string().required().description('JWT secret key'),
|
||||
|
@ -2,17 +2,19 @@ const httpStatus = require('http-status');
|
||||
const pick = require('../utils/pick');
|
||||
const ApiError = require('../utils/ApiError');
|
||||
const catchAsync = require('../utils/catchAsync');
|
||||
const { mealService } = require('../services');
|
||||
const { mealService, profileService } = require('../services');
|
||||
|
||||
const createMeal = catchAsync(async (req, res) => {
|
||||
req.body.user = req.user._id;
|
||||
const meal = await mealService.createMeal(req.body);
|
||||
res.status(httpStatus.CREATED).send(meal);
|
||||
const { dailyCalories } = await profileService.getProfileByUserId(req.user._id);
|
||||
res.status(httpStatus.CREATED).send({ meal, dailyCalories });
|
||||
});
|
||||
|
||||
const getMeals = catchAsync(async (req, res) => {
|
||||
const meals = await mealService.getMealsByDate(req.user._id, req.query.date);
|
||||
res.send(meals);
|
||||
const { dailyCalories } = await profileService.getProfileByUserId(req.user._id);
|
||||
res.send({ meals, dailyCalories });
|
||||
});
|
||||
|
||||
const getAllMeals = catchAsync(async (req, res) => {
|
||||
@ -38,7 +40,7 @@ const updateMeal = catchAsync(async (req, res) => {
|
||||
const updateMealProducts = catchAsync(async (req, res) => {
|
||||
const meal = await mealService.updateMealProductsById(req.params.mealId, req.body);
|
||||
res.send(meal);
|
||||
})
|
||||
});
|
||||
|
||||
const deleteMeal = catchAsync(async (req, res) => {
|
||||
await mealService.deleteMealById(req.params.mealId);
|
||||
|
@ -6,7 +6,7 @@ const logger = require('./config/logger');
|
||||
let server;
|
||||
mongoose.connect(config.mongoose.url, config.mongoose.options).then(() => {
|
||||
logger.info('Connected to MongoDB');
|
||||
server = app.listen(config.port, () => {
|
||||
server = app.listen(config.port, config.hostname,() => {
|
||||
logger.info(`Listening to port ${config.port}`);
|
||||
});
|
||||
});
|
||||
|
@ -9,7 +9,7 @@ const products = Joi.object().keys({
|
||||
|
||||
const createMeal = {
|
||||
body: Joi.object().keys({
|
||||
label: Joi.string().required().valid('breakfast', 'lunch', 'dinner', 'supper', 'snack I', 'snack II', 'snack III'),
|
||||
label: Joi.string().required().valid('breakfast', 'lunch', 'dinner', 'supper'),
|
||||
products: Joi.array().items(products).required(),
|
||||
date: Joi.date(),
|
||||
}),
|
||||
@ -34,7 +34,7 @@ const updateMeal = {
|
||||
body: Joi.object()
|
||||
.keys({
|
||||
user: Joi.string().custom(objectId).required(),
|
||||
label: Joi.string().required().valid('breakfast', 'lunch', 'dinner', 'supper', 'snack I', 'snack II', 'snack III'),
|
||||
label: Joi.string().required().valid('breakfast', 'lunch', 'dinner', 'supper'),
|
||||
products: Joi.array().items(products).required(),
|
||||
date: Joi.date().required(),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user