File size: 1,037 Bytes
a98870b
4ad9c00
a98870b
b820eb3
a98870b
 
 
 
 
 
 
 
 
7ae259a
a98870b
a442d57
 
 
 
 
 
4ad9c00
 
b820eb3
 
 
 
 
 
 
 
 
 
 
7ae259a
b820eb3
 
 
a442d57
a98870b
b820eb3
a442d57
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
40
41
42
43
const Glucosa = require("../models/glucosa.js");

/**
 * @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({});
    }
    res.json(registros);
  } catch (error) {
    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) {
    res.status(500).json({ error: "Error al ingresar el registro de glucosa" });
  }
}

module.exports = {
  getGlucosaByIdUser,
  postOneRegisterGlucosa,
};