mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-20 00:29:45 -06:00
Merge pull request #289 from MuhammadKhalilzadeh/limit-checks
Limit checks
This commit is contained in:
@@ -48,7 +48,7 @@ You can see the designs [here](https://www.figma.com/design/RPSfaw66HjzSwzntKcgD
|
||||
###### Monitors
|
||||
- <code>GET</code> [/api/v1/monitors](#get-monitors)
|
||||
- <code>GET</code> [/api/v1/monitor/{id}](#get-monitor-id)
|
||||
- <code>GET</code> [/api/v1/monitors/user/{userId}](#get-monitors-user-userid)
|
||||
- <code>GET</code> [/api/v1/monitors/user/{userId}?limit](#get-monitors-user-userid)
|
||||
- <code>POST</code> [/api/v1/monitors](#post-monitors)
|
||||
- <code>POST</code> [/api/v1/monitors/delete/{monitorId}](#post-monitors-del-id)
|
||||
- <code>POST</code> [/api/v1/monitors/edit/{monitorId}](#post-monitors-edit-id)
|
||||
@@ -749,7 +749,7 @@ curl --request GET \
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary id='get-monitors-user-userid'><code>GET</code> <b>/api/v1/monitors/user/{userId}</b></summary>
|
||||
<summary id='get-monitors-user-userid'><code>GET</code> <b>/api/v1/monitors/user/{userId}?limit</b></summary>
|
||||
|
||||
###### Method/Headers
|
||||
|
||||
@@ -767,7 +767,7 @@ curl --request GET \
|
||||
|
||||
```
|
||||
curl --request GET \
|
||||
--url http://localhost:5000/api/v1/monitors/user/6645079aae0b439371913972 \
|
||||
--url http://localhost:5000/api/v1/monitors/user/6645079aae0b439371913972?limit=25 \
|
||||
--header '<bearer_token>' \
|
||||
```
|
||||
|
||||
|
||||
@@ -293,15 +293,26 @@ const getMonitorById = async (req, res) => {
|
||||
*/
|
||||
const getMonitorsByUserId = async (req, res) => {
|
||||
try {
|
||||
const limit = req.body.limit;
|
||||
const monitors = await Monitor.find({ userId: req.params.userId });
|
||||
// Map each monitor to include its associated checks
|
||||
const monitorsWithChecks = await Promise.all(
|
||||
monitors.map(async (monitor) => {
|
||||
// Checks are order oldest -> newest
|
||||
const checks = await Check.find({ monitorId: monitor._id }).sort({
|
||||
createdAt: 1,
|
||||
});
|
||||
return { ...monitor.toObject(), checks };
|
||||
|
||||
if(limit) {
|
||||
// Checks are order oldest -> newest
|
||||
const checks = await Check.find({ monitorId: monitor._id }).sort({
|
||||
createdAt: 1,
|
||||
}).limit(limit);;
|
||||
return { ...monitor.toObject(), checks };
|
||||
|
||||
} else {
|
||||
// Checks are order oldest -> newest
|
||||
const checks = await Check.find({ monitorId: monitor._id }).sort({
|
||||
createdAt: 1,
|
||||
});
|
||||
return { ...monitor.toObject(), checks };
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ const Monitor = require("../models/Monitor");
|
||||
|
||||
router.get("/", monitorController.getAllMonitors);
|
||||
router.get("/:monitorId", monitorController.getMonitorById);
|
||||
router.get("/user/:userId", monitorController.getMonitorsByUserId);
|
||||
router.get("/user/:userId?limit", monitorController.getMonitorsByUserId);
|
||||
|
||||
router.post("/", monitorController.createMonitor);
|
||||
router.post(
|
||||
|
||||
Reference in New Issue
Block a user