Please help me with this problem

exports.findAll = (req, res) => {

  const username = req.query.username;

  var condition = username ? { username: { [Op.like]: `%${username}%` } } : null;

  User.findAll({ where: condition })

    .then(user => {

      user.forEach(user => {

      var authorities = [];

      var department = [];

      var typecontract = [];

      user.getRoles().then(roles => {

        user.getServices().then(services => {

          user.getContrats().then(contrats => {

        for (let i = 0;i < contrats.length && services.length && i < roles.length; i++) {

          authorities.push("ROLE_" + roles[i].name.toUpperCase());

          department.push("DEPARTMENT_" + services[i].name.toUpperCase());

          typecontract.push("CONTRAT_" + contrats[i].name.toUpperCase());

        }

        res.send({

          id: user.id,

          username: user.username,

          userlastname : user.userlastname,

          phone : user.phone,

          solde : user.solde,

          email: user.email,

          roles: authorities,

          services: department,

          contrats: typecontract,

        })

      }) }) })

     }) })

    .catch(err => {

      res.status(500).send({

        message:

          err.message || "Some error occurred while retrieving users."

      });

    });

};

I’m having the same issue here

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hi @Tralin !

Welcome to the forum!

I have moved your question to another post since that last thread hasn’t been active for over a year.

I would suggest adding some details to the body of the post explaining what you are having issues with.

You can also change the title of this post to something more descriptive to your problem if you like.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.