Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.
Prev Previous commit
Next Next commit
Level 3 in progress
  • Loading branch information
nataliiazab committed Apr 11, 2023
commit 3f3f613213ee6c4bf14703ffe7132ab5dd63e2bd
15 changes: 15 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ app.delete("/messages/:id", function (request, response) {
// response.status(200).send({ message });
});

/*to search messages by text*/
app.get("/messages/search", function (req, res) {
const searchText = req.query.text;
const matchingMessages = messages.filter(
(message) => message.text.indexOf(searchText) !== -1
);
res.status(200).send({ messages: matchingMessages });
});

/*to get the latest 10 messages*/
app.get("/messages/latest", function (req, res) {
const latestMessages = messages.slice(-10);
res.status(200).send({ messages: latestMessages });
});

// const PORT = 9090;
// app.listen(process.env.PORT);

Expand Down