Merge pull request #289 from MuhammadKhalilzadeh/limit-checks
Limit checks
This commit is contained in:
3 files changed
+20
-9
No files matched your search
@@ -48,7 +48,7 @@ You can see the designs [here](https://www.figma.com/design/RPSfaw66HjzSwzntKcgD
|
|||||||
###### Monitors
|
###### Monitors
|
||||||
- <code>GET</code> [/api/v1/monitors](#get-monitors)
|
- <code>GET</code> [/api/v1/monitors](#get-monitors)
|
||||||
- <code>GET</code> [/api/v1/monitor/{id}](#get-monitor-id)
|
- <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](#post-monitors)
|
||||||
- <code>POST</code> [/api/v1/monitors/delete/{monitorId}](#post-monitors-del-id)
|
- <code>POST</code> [/api/v1/monitors/delete/{monitorId}](#post-monitors-del-id)
|
||||||
- <code>POST</code> [/api/v1/monitors/edit/{monitorId}](#post-monitors-edit-id)
|
- <code>POST</code> [/api/v1/monitors/edit/{monitorId}](#post-monitors-edit-id)
|
||||||
@@ -749,7 +749,7 @@ curl --request GET \
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<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
|
###### Method/Headers
|
||||||
|
|
||||||
@@ -767,7 +767,7 @@ curl --request GET \
|
|||||||
|
|
||||||
```
|
```
|
||||||
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>' \
|
--header '<bearer_token>' \
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+16
-5
@@ -293,15 +293,26 @@ const getMonitorById = async (req, res) => {
|
|||||||
*/
|
*/
|
||||||
const getMonitorsByUserId = async (req, res) => {
|
const getMonitorsByUserId = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const limit = req.body.limit;
|
||||||
const monitors = await Monitor.find({ userId: req.params.userId });
|
const monitors = await Monitor.find({ userId: req.params.userId });
|
||||||
// Map each monitor to include its associated checks
|
// Map each monitor to include its associated checks
|
||||||
const monitorsWithChecks = await Promise.all(
|
const monitorsWithChecks = await Promise.all(
|
||||||
monitors.map(async (monitor) => {
|
monitors.map(async (monitor) => {
|
||||||
// Checks are order oldest -> newest
|
|
||||||
const checks = await Check.find({ monitorId: monitor._id }).sort({
|
if(limit) {
|
||||||
createdAt: 1,
|
// Checks are order oldest -> newest
|
||||||
});
|
const checks = await Check.find({ monitorId: monitor._id }).sort({
|
||||||
return { ...monitor.toObject(), checks };
|
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("/", monitorController.getAllMonitors);
|
||||||
router.get("/:monitorId", monitorController.getMonitorById);
|
router.get("/:monitorId", monitorController.getMonitorById);
|
||||||
router.get("/user/:userId", monitorController.getMonitorsByUserId);
|
router.get("/user/:userId?limit", monitorController.getMonitorsByUserId);
|
||||||
|
|
||||||
router.post("/", monitorController.createMonitor);
|
router.post("/", monitorController.createMonitor);
|
||||||
router.post(
|
router.post(
|
||||||
|
|||||||
Reference in new issue
Block a user