'Calling a stored procedure doesn't get parameters for a POST and send them all NULL

I need a little bit of help here because I don't know what it's going on wrong.

To get some context: we are creating a new project, where we use models and controllers to get the data. Right now, we have the database is hosted on Heroku, and when we run the same query that it's giving us a problem it works but on Datagrip (database manager from Jetbrains). But when we try to insert parameters from the model to create a user using Postman it gives this issue:

"message": "null value in column "nombre" of relation "usuario" violates not-null constraint"`

Here's the code of the model for this route:

const { password } = require("pg/lib/defaults");
var pool = require("../server.js");

var UsuarioCliente = function(
    nombres,
    apellidos,
    password,
    email,
    sexos,
    edades,
    direccion_residencia
) {
    this.Nombres = nombres;
    this.Apellidos = apellidos;
    this.Password = password;
    this.Email = email;
    this.Sexos = sexos;
    this.Edades = edades;
    this.Direccion_Residencia = direccion_residencia;
};

UsuarioCliente.Crear = (newUsuario, result) => {
    
    const SP2 = `CALL Create_Usuario_Cliente($1, $2, $3, $4, $5, $6, $7);`;
    const SPInsert =
        "INSERT INTO usuario (nombre, apellido, contraseña, sexo, edad, direccion_de_residencia) VALUES ($1, $2, $3, $4, $5, $6, $7)";
    const values = [
        newUsuario.Nombres,
        newUsuario.Apellidos,
        newUsuario.Password,
        newUsuario.Email,
        newUsuario.Sexos,
        newUsuario.Edades,
        newUsuario.Direccion_Residencia,
    ];

    pool.query(
        SP2, [
            newUsuario.Nombres,
            newUsuario.Apellidos,
            newUsuario.Password,
            newUsuario.Email,
            newUsuario.Sexos,
            newUsuario.Edades,
            newUsuario.Direccion_Residencia,
        ],
        (err, res) => {
            if (err) {
                console.log("error: ", err);
                result(err, null);
                return;
            }
            console.log("Usuario creado exitosamente");
        }
    );
};

module.exports = UsuarioCliente;

I tried the same thing in different forms:

  1. I tried to use the query SP2 and pass the const values to the pool.query and that didn't work.
  2. I tried (the last thing that I did, that's why it's still there) passing the values as an array in the same pool.query.
  3. I tried using an INSERT and not the stored procedure, but it gives back the same error.

I'm gonna post here the controller for this model if anybody needs to see it too:

var pool = require("../server.js");
const express = require("express");
const app = express();
const UsuarioCliente = require("../models/UsuarioClienteModelo");

exports.Crear = (req, res) => {
    if (!req.body) {
        res.status(400).send({
            message: "El contenido esta vacio.",
        });
    }
    const nuevoUsuario = new UsuarioCliente(
        req.body.Nombres,
        req.body.Apellidos,
        req.body.Password,
        req.body.Email,
        req.body.Sexos,
        req.body.Edades,
        req.body.Direccion_Residencia
    );

    UsuarioCliente.Crear(nuevoUsuario, (err, data) => {
        if (err) {
            res.status(500).send({
                message: err.message || "Ocurrio un error al momento de crear el usuario.",
            });
            console.log(err);
        } else {
            res.send(data);
        }
    });
};

Here is the error that we get via console:

error: null value in column "nombre" of relation "usuario" violates not-null constraint

at Parser.parseErrorMessage (C:\RepositorioLocal\furniture-insight-backend\node_modules\pg-protocol\dist\parser.js:287:98)
at Parser.handlePacket (C:\RepositorioLocal\furniture-insight-backend\node_modules\pg-protocol\dist\parser.js:126:29)
at Parser.parse (C:\RepositorioLocal\furniture-insight-backend\node_modules\pg-protocol\dist\parser.js:39:38)
at TLSSocket. (C:\RepositorioLocal\furniture-insight-backend\node_modules\pg-protocol\dist\index.js:11:42)
at TLSSocket.emit (node:events:379:20)
at addChunk (node:internal/streams/readable:313:12)
at readableAddChunk (node:internal/streams/readable:288:9)
at TLSSocket.Readable.push (node:internal/streams/readable:227:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 232,
severity: 'ERROR',
code: '23502',
detail: 'Failing row contains (52, null, null, null, null, null, null).',
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: 'public',
table: 'usuario',
column: 'nombre',
dataType: undefined,
constraint: undefined,
file: 'execMain.c',
line: '1947',
routine: 'ExecConstraints'



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source