const Glucosa = require("../models/glucosa.js"); /** * @description Obtener todos los registros de glucosa * * @param {import("express").Request} req * @param {import("express").Response} res */ async function getAllGlucosa(req, res) { try { const registros = await Glucosa.find(); if (registros.length == 0) { res.json({ message: "No hay registros existentes de glucosa" }); } res.json(registros); } catch (error) { console.error("Error al conectar a MongoDB:", error.message); res .status(500) .json({ error: "Error al obtener los registros de glucosa" }); } } /** * @description Obtener todos los registros de glucosa de un usuario * * @param {import("express").Request} req * @param {import("express").Response} res */ async function getGlucosaByIdUser(req, res) { const userId = req.params.iduser; try { const registros = await Glucosa.find({ iduser: userId }); if (registros.length == 0) { res.json({ message: "El usuario no tiene registros de glucosa" }); } res.json(registros); } catch (error) { console.error("Error al conectar a MongoDB:", error.message); res .status(500) .json({ error: "Error al obtener los registros de glucosa" }); } } /** * @description Registra un dato de glucosa * * @param {import("express").Request} req * @param {import("express").Response} res */ async function postOneRegisterGlucosa(req, res) { try { await Glucosa.create(req.body); res.json({ message: "Ok, datos ingresados" }); } catch (error) { console.error("Error al crear registro glucosa:", error); res .status(500) .json({ error: "Error al obtener los registros de glucosa" }); } } module.exports = { getAllGlucosa, getGlucosaByIdUser, postOneRegisterGlucosa, };