Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
487 B
3
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 lowerCaseQ = q.toLowerCase();
  const talker = talkersList.filter((t) => t.name.toLowerCase().includes(lowerCaseQ));
  if (talker.length === 0) {
    return res.status(404).json({ message: 'Pessoa palestrante não encontrada' });
  }
  return res.status(200).json(talker);
});
Leave a Comment