Untitled

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

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