Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

302
Views
Express DELETE 500 (Error interno del servidor)

Estoy tratando de eliminar mi User del sistema, pero recibo el error 500 (Error interno del servidor)

Intenté esto con mi Product y todavía funciona bien. No sabía dónde me equivoqué.

A continuación se muestra mi código

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>

Y esto es lo que obtengo de Console.log

OBTENER http://localhost:5000/admin/user-list/remove/2?user_id=2 500 (Error interno del servidor)

Probé con router.delete y method: 'delete' en el script pero obtengo el mismo resultado. ¿Dónde he encontrado el problema? Tengo una tabla de productos, tengo user_id como clave externa, ¿es un problema?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!