owned this note changed 2 years ago
Published Linked with GitHub

Getting an artist by id with pg

// src/controllers/artist.js ... const getArtistById = async (req, res) => { try { const { id } = req.params const { rows: [ artist ] } = await db.query('SELECT * FROM Artists WHERE id = $1', [ id ]) if (!artist) { return res.status(404).json({ message: `artist ${id} does not exist` }) } res.status(200).json(artist) } catch (err) { res.status(500).json(err.message) } } module.exports = { ..., ..., getArtistById } ...
// src/routes/artist.js ... router.get('/:id', artistController.getArtistById); ...
Select a repo