PG-Promise Proc Erroring Out with Unknown Parameter Type

310 Views Asked by At

We are attempting to write a PostgreSQL Procedure to insert data into a table. We have created the procedure and ran said procedure with the variables below and it inserts just fine. However, when we try to use pg-promise with our express server, our string parameters are being read as unknown. When we iterate over the post body, we see that each parameter is reading as the type we expect to go in, and PostgreSQL is reading integer correctly, but it isn't reading string correctly. I've attempted to use the as.text function and it sends in the parameter value as "''" but that still reads as unknown. Is there something we are missing to successfully post the data?

let createInspection = async (req, res, next) => {
  try {
    let params = [];
    for (let prop in req.body) {
      console.log(typeof req.body[prop]);
      params.push(req.body[prop]);
    }
    console.log(params)
    let data = await db.proc('Inspections_Create', params);
    res.status(200)
    .json({
      status: 'success',
      data: data,
      message: 'Inserted Inspection'
    });
  }
  catch (error) {
    return next(error);
  }
}

enter image description here

0

There are 0 best solutions below