Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
486 B
2
Indexable
Never
app.delete('/talker/:id', tokenValid, async (request, response) => {
  const { id } = request.params;
  const data = await fs.readFile(path.join(__dirname, ARQUIVO), 'utf-8');
  const talkers = JSON.parse(data);
  const index = talkers.findIndex((talkId) => talkId.id === Number(id));
  talkers.splice(index, 1);
  await fs.writeFile(path.join(__dirname, ARQUIVO), JSON.stringify(talkers));
  return response.status(204).json({ message: 'Pessoa palestrante deletada com sucesso' });
});
Leave a Comment