I have received the data from frontend. So all the data is in req.body. First I map it then I am trying to insert it. But gives the error.
router.post('/addItems', (req, res) => {
let purchase_id = '';
let item_code = '';
let item_name = '';
let description = '';
let category_id = '';
let location_id = '';
let invoice_no = '';
let warrantyend_Date = '';
let created_by = '';
let item_status = '';
let complain_id = '';
console.log(req.body);
req.body.map((results)=>{
this.purchase_id = results.purchase_id;
this.item_code = results.item_code;
this.item_name = results.item_name;
this.description = results.description;
this.category_id = results.category_id;
this.location_id = results.location_id;
this.invoice_no = results.invoice_no;
this.warrantyend_Date = results.warrantyend_Date;
this.created_by = results.created_by
this.item_status = results.item_status;
this.complain_id = results.complain_id;
console.log('results----',results);
})
If possible then also gave me idea, how to wrote procedure for it in postgreSQL.
you can change the input type to jsonb[] and modify the function accordingly. Here's the updated PostgreSQL function:
Now, to call this function from Node.js, you should first convert each object in the req.body array to a JSON string and then pass the modified array as an argument to the function: