i used reactjs, nodejs, express and postgress with knex
here's the code
app.post('/new-story', (req, res) => {
const {title, description, mature, id} = req.body;
db.select('stories').from('users').where('id' = id)
.then(data => {
const stories = data[0].stories;
db('story')
.returning('*')
.insert({
title: title,
category: category,
description: description,
mature: mature,
entry: stories
})
.then(story => {
res.json(story)
})
})
.catch(err => console.log(err))
})
and i receive and error
error: invalid input syntax for integer: "" at Connection.parseE, at Connection.parseMessage, at Socket,
here's the code in my react app
onSaveDate = () => {
fetch('http://localhost:3001/new-story', {
method: 'post',
header: {'Content-Type' : 'application/json'},
body: JSON.stringify({
id: this.state.id,
title: this.state.title,
description: this.state.description,
category: this.state.category,
mature: this.state.mature
})
})
.then(response => response.json())
.then(story => console.log(story))
}
i tried to test my end point in postman and it worked, idk when i tried in my react app it said error: invalid input syntax for integer: ""
and here's the database
CREATE TABLE users (
id serial primary key,
name VARCHAR(100),
email text unique not null,
stories bigint default 0,
joined timstamp not null
);
and here's my table story
CREATE TABLE users (
id_book serial primary key,
entry bigint default 0,
title varchar(100),
category varchar(100),
description varchar(100),
mature varchar(10)
);
what i would like to is stories and entry to be the same, i cannot figure out the error in postgress node