LOGIN ROUTE ERROR

Asked

Viewed 41 times

-3

Hello, I am a student of programming, and during a project I came across a mistake that I cannot solve. I am basically in the creation part of "login" route, whose purpose is to search in the database if an "id" exists or not. I am using INSOMNIA , sending as JSON {"id":"7ae8303f"}, in case the id of a created user.

const connection = require('../database/connection');

module.exports= {
     async create(request, response) {
        const { id } = request.body;

        const ong = await connection('ongs')
            .where('id', id)
            .select('ong_id')
            .first();

        if (!ong)  {
            return response.status(400).json({ error: 'No ONG found with this ID'});
        }

        return response.json(ong);
    }
};  

ERROR : (Node:20832) Unhandledpromiserejectionwarning: Error: Undefined Binding(s) Detected when compiling FIRST. Undefined column(s): [id] query: select ong_id from ongs Where id = ? limit ? At querycompiler_sqlite3.toSQL (C: Users Mathe Documents projects backend node_modules knex lib query Compiler.js:99:13) at Builder.toSQL (C: Users Mathe Documents projects backend node_modules knex lib query Builder.js:72:44) AT: Users Mathe Documents projects backend node_modules knex lib Runner.js:31:36 AT: Users Mathe Documents projects backend node_modules knex lib Runner.js:260:24 at async create (C: Users Mathe Documents projects backend src controllers Sessioncontroller.js:7:21) (Ode:20832) Unhandledpromiserejectionwarning: Unhandled Promise rejection. This error either originated by Throwing Inside of an async Function without a catch block, or by rejecting a Promise which was not handled with . catch(). (rejection id: 2) (Ode:20832) [DEP0018] Deprecationwarning: Unhandled Promise rejections are deprecated. In the Future, Promise rejections that are not handled will terminate the Node.js process with a non-zero Exit code.

1 answer

-1

Friend, this route would be a GET ? if yes, you should pass the parameter by the route or by query params and not in the request body.

Only POST and PUT has body.

The GET and DELETE has parameters and/or query params.

To do this you need to create the route passing which will receive a parameter, Ex:

routes.get('/users/:id', (request, response) => {
  const { id } = request.params;

  // Faça a query aqui 
}

Ai yes can pick up within the route the parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.