E-Commerce App: REST API - Handling PUT Requests

I’m currently working on the first part of the e-commerce app portfolio project where you build a REST API for a theoretical e-commerce app/website.

I’ve started work on the CRUD operations for the users table in my database. I’ve done the basic implementation for GETs, POSTs, and DELETEs on the users table, but I’m feeling a bit stuck on PUTs. For the other operations, the same parameter(s), if any, are always used (i.e. either email and password together or just email - I’m using email as the primary key for users).

However, I’m finding it difficult to wrap my head around how to approach editing an existing user’s data because the user would not always want to edit the same data.

For clarification on what I mean, here’s my code (again, a basic implementation only so far) for DELETEing a specified user’s info:

app.delete("/users/:userEmail", async (req, res) => {
  const { userEmail } = req.params;
  
  try {
    const query = 'DELETE FROM users WHERE email = $1'
    const values = [`${userEmail}`]
    const user = await db.query(query, values);
    
    if (!user) {
      return res.send("No user with that email.");
    }

    res.sendStatus(204)
  } catch (err) {
    console.log(err.stack);
    res.status(500).json({ msg: "Failed" });
  }
})

Now, if I wanted to edit a user’s info, I can’t know for sure which data they’d be wanting to edit, so I’d need to account for any one of the columns being edited and sometimes they might want to change only one column and other times they might want to change multiple columns. How is this typically handled/solved?

I guess what I’m wondering is, is there a way to change multiple columns for a given record with a single query that accepts parameters conditionally or can you only change one column at a time?

You can pass what you want to update in req.body, not in req.params.