const express = require("express");
const router = express.Router();

const userService = require("../services/userService");
const globalService = require("../services/globalService");

router.get("/read/id/:idUser", async (req, res) => {
  const idUser = req.params.idUser;

  try {
    const user = await userService.getUserById(idUser);

    res.json({ valid: Boolean(user), user });
  } catch (error) {
    res.status(500).json({ valid: false, error: "Internal Server Error" });
  }
});

router.get("/read/matricule/:matricule", async (req, res) => {
  const matriculeUser = req.params.matricule;

  try {
    const user = await userService.getUserByMatricule(matriculeUser);

    res.json({ valid: Boolean(user), user });
  } catch (error) {
    res.status(500).json({ valid: false, error: "Internal Server Error" });
  }
});

module.exports = router;
