Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

310
Vistas
Express DELETE 500 (Internal Server Error)

I'm trying to Remove my User from the system, but I'm getting error 500 (Internal Server Error)

I tried this with my Product and it still works fine. I didn't know where did I go wrong?

Below is my code

Router

router.get('/user-list/remove/:user_id', adminController.removeUser);

Service

async removeUser(user_id) {
    const userInDb = await this.userRepository.getById(user_id);
    if (userInDb) {
        await userInDb.destroy();
    } else {
        throw new Error();
    }
}

Controller

const removeUser = async (req, res) => {
try {
    const adminService = new AdminService();
    const data = req.params.user_id;
    await adminService.removeUser(data);
    res.send();
} catch (error) {
    res.status(500).json({ TRAVE: true, message: error });
}}

EJS

<a>
    <button class="deletebutton" value="<%= users[i].user_id %>">Delete</button>
</a>

<script type="text/javascript">
            $('.deletebutton').on("click", function (event) {
                event.preventDefault();
                var user_id = $(this).val();
                if (confirm("Are you sure you want to delete this data?")) {
                    $.ajax({
                        url: `/admin/user-list/remove/${user_id}`,
                        method: 'get',
                        data: { user_id: user_id },
                        success: function (data, textStatus, xhr) {
                            if (xhr.status == 200 || xhr.status == '200') {
                                $('.notification').html(`Delete done!`)
                            } else {
                                alert('Some error occurred try again');
                            }
                        },
                        error: function (response) {
                            error.html(`${response.responseJSON.message}`);
                        }
                    });
                }
            });
        </script>

And this is what I get from Console.log

GET http://localhost:5000/admin/user-list/remove/2?user_id=2 500 (Internal Server Error)

I tried with router.delete and method: 'delete' in the script but I get the same result. Where have I encountered the problem? I have a Product table, I have user_id as a foreign key, is it a problem?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda