Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用knex postgres更新两个表_Javascript_Node.js_Reactjs_Postgresql_Knex.js - Fatal编程技术网

Javascript 使用knex postgres更新两个表

Javascript 使用knex postgres更新两个表,javascript,node.js,reactjs,postgresql,knex.js,Javascript,Node.js,Reactjs,Postgresql,Knex.js,我有两个表,当用户更新其姓名、年龄和电子邮件时,我想更新它们。电子邮件在两个表中login和users我使用的是knex和Postgres 我尝试在我的node.js文件中使用下面的代码同时更新两个表 const handleProfileUpdate = (req, res, db) => { const { id } = req.params; const { name, age, email } = req.body.formInput; db('users')

我有两个表,当用户更新其
姓名
年龄
电子邮件
时,我想更新它们。电子邮件在两个表中
login
users
我使用的是knex和Postgres

我尝试在我的
node.js
文件中使用下面的代码同时更新两个表

const handleProfileUpdate = (req, res, db) => {
  const { id } = req.params;
  const { name, age, email } = req.body.formInput;
  db('users')
    .where({ id })
    .update({ name, email })
    .then((response) => {
      response
        ? res.status(201).send('success')
        : res.status(400).send({ error: 'unable to update' });
    })
    .catch((err) => res.status(400).send({ error: 'Error updating user' }));

  db('login')
    .where({ id })
    .update({ email })
    .then((response) => {
      response
        ? res.status(201).send('success')
        : res.status(400).send({ error: 'unable to update email' });
    })
    .catch((err) =>
      res.status(400).send({ error: 'Error updating user email' })
    );
};
但是,问题是,当我在表单上单击“保存”时,我可以在配置文件中看到更新的名称,但在电子邮件中看不到更新的名称。但是当我注销并再次尝试登录时,我看到以下错误

Signin.jsx:22 POSThttp://localhost:3000/signin net::ERR_EMPTY_响应
和`无法获取

问题是两个表中的实际电子邮件都没有更新

这是前端上的代码,它点击端点以更新用户数据

const onProfileUpdate = (data) => {
    fetch(`http://localhost:3000/profile/${user.id}`, {
      method: 'post',
      headers: { 'content-type': 'application/json' },
      body: JSON.stringify({ formInput: data }),
    })
      .then((res) => {
        toggleModal();
        loadUser({ ...user, ...data });
      })
      .catch((error) => {
        console.error(error);
      });
  };
实现此功能的最佳方式是什么