Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
511 B
2
Indexable
Never
app.get('/talker/search', tokenValidate, async (req, res) => {
  const { q } = req.query;
  const data = fs.readFileSync(path.join(__dirname, FILE_NAME), 'utf-8');
  const talkersList = JSON.parse(data);
  const talker = talkersList.filter((t) => t.name.includes(q));
  if (typeof q === 'undefined') {
    return res.status(200).json(talkersList);
  }
  if (talker.length === 0) {
    return res.status(404).json({ message: 'Pessoa palestrante não encontrada' });
  }
  return res.status(200).json(talker);
});
Leave a Comment