Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
482 B
2
Indexable
Never
// requisito 2
app.get('/talker/:id', async (request, response) => {
  const { id } = request.params;
  const data = await fs.readFile(path.join(__dirname, 'talker.json'), 'utf-8');
  const talkers = JSON.parse(data);

  if (!talkers) response.status(200).json([]);
  const talker = talkers.find((talk) => talk.id === Number(id));
  if (!talker) {
    response.status(404).json({ message: 'Pessoa palestrante não encontrada' }); 
  }
  return response.status(200).json(talker);
});
Leave a Comment