Spaces:
Runtime error
Runtime error
File size: 857 Bytes
7ae259a |
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 38 39 |
const Alimento = require("../models/alimento.js");
/**
*
* @param {import("express").Request} req
* @param {import("express").Response} res
*/
async function getFoodByUserID(req, res) {
const { iduser } = req.params;
try {
const alimentos = await Alimento.find({ iduser: iduser });
if (alimentos.length == 0) {
res.json({});
}
res.json(alimentos);
} catch (error) {
res.status(500).json({ error: "Error al optner los alimentos" });
}
}
/**
*
* @param {import("express").Request} req
* @param {import("express").Response} res
*/
async function postOneFood(req, res) {
try {
await Alimento.create(req.body);
res.json({ message: "Ok, datos ingresados" });
} catch (error) {
res.status(500).json({ error: "Error al ingresar alimento" });
}
}
module.exports = {
postOneFood,
getFoodByUserID,
};
|