---
# System prepended metadata

title: Updating an artist by id
tags: [' solution', ' track', music-library]

---

---
tags: music-library, solution, track
---


# Updating an artist by id

```javascript=
// src/controllers/artist.js
...
exports.update = async (req, res) => {
  const db = await getDb();
  const data = req.body;
  const { artistId } = req.params;

  try {
    const [
      { affectedRows },
    ] = await db.query('UPDATE Artist SET ? WHERE id = ?', [data, artistId]);

    if (!affectedRows) {
      res.sendStatus(404);
    } else {
      res.status(200).send();
    }
  } catch (err) {
    res.sendStatus(500);
  }

  db.end();
};
...
```

```javascript=
// src/routes/artist.js
...
router.patch('/:artistId', artistController.update);
...
```