chartManD commited on
Commit
b820eb3
·
1 Parent(s): a98870b

se crea post directo para registro de glucosa

Browse files
Files changed (2) hide show
  1. main.js +2 -0
  2. src/controllers/glucosa-controller.js +21 -0
main.js CHANGED
@@ -6,6 +6,7 @@ const connectDB = require("./src/database/conection.js");
6
  const {
7
  getAllGlucosa,
8
  getGlucosaByIdUser,
 
9
  } = require("./src/controllers/glucosa-controller.js");
10
 
11
  connectDB();
@@ -30,6 +31,7 @@ app.get("/api/", (req, res) => {
30
  });
31
 
32
  app.get("/api/glucosa", getAllGlucosa);
 
33
  app.get("/api/glucosa/:iduser", getGlucosaByIdUser);
34
 
35
  app.listen(PORT, () => {
 
6
  const {
7
  getAllGlucosa,
8
  getGlucosaByIdUser,
9
+ postOneRegisterGlucosa,
10
  } = require("./src/controllers/glucosa-controller.js");
11
 
12
  connectDB();
 
31
  });
32
 
33
  app.get("/api/glucosa", getAllGlucosa);
34
+ app.post("/api/glucosa", postOneRegisterGlucosa);
35
  app.get("/api/glucosa/:iduser", getGlucosaByIdUser);
36
 
37
  app.listen(PORT, () => {
src/controllers/glucosa-controller.js CHANGED
@@ -1,6 +1,7 @@
1
  const Glucosa = require("../models/glucosa.js");
2
 
3
  /**
 
4
  *
5
  * @param {import("express").Request} req
6
  * @param {import("express").Response} res
@@ -21,6 +22,7 @@ async function getAllGlucosa(req, res) {
21
  }
22
 
23
  /**
 
24
  *
25
  * @param {import("express").Request} req
26
  * @param {import("express").Response} res
@@ -41,7 +43,26 @@ async function getGlucosaByIdUser(req, res) {
41
  }
42
  }
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  module.exports = {
45
  getAllGlucosa,
46
  getGlucosaByIdUser,
 
47
  };
 
1
  const Glucosa = require("../models/glucosa.js");
2
 
3
  /**
4
+ * @description Obtener todos los registros de glucosa
5
  *
6
  * @param {import("express").Request} req
7
  * @param {import("express").Response} res
 
22
  }
23
 
24
  /**
25
+ * @description Obtener todos los registros de glucosa de un usuario
26
  *
27
  * @param {import("express").Request} req
28
  * @param {import("express").Response} res
 
43
  }
44
  }
45
 
46
+ /**
47
+ * @description Registra un dato de glucosa
48
+ *
49
+ * @param {import("express").Request} req
50
+ * @param {import("express").Response} res
51
+ */
52
+ async function postOneRegisterGlucosa(req, res) {
53
+ try {
54
+ await Glucosa.create(req.body);
55
+ res.json({ message: "Ok, datos ingresados" });
56
+ } catch (error) {
57
+ console.error("Error al crear registro glucosa:", error);
58
+ res
59
+ .status(500)
60
+ .json({ error: "Error al obtener los registros de glucosa" });
61
+ }
62
+ }
63
+
64
  module.exports = {
65
  getAllGlucosa,
66
  getGlucosaByIdUser,
67
+ postOneRegisterGlucosa,
68
  };