Fixed non functioning code
This commit is contained in:
1 parent
7462458eca
commit
12e85aed03
3 files changed
+16
-13
No files matched your search
@@ -50,11 +50,14 @@ export const getMonitorsByUserId = createAsyncThunk(
|
|||||||
async (token, thunkApi) => {
|
async (token, thunkApi) => {
|
||||||
const user = jwtDecode(token);
|
const user = jwtDecode(token);
|
||||||
try {
|
try {
|
||||||
const res = await axiosInstance.get("/monitors/user/" + user._id, {
|
const res = await axiosInstance.get(
|
||||||
headers: {
|
`/monitors/user/${user._id}?limit=25`,
|
||||||
Authorization: `Bearer ${token}`,
|
{
|
||||||
},
|
headers: {
|
||||||
});
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.data) {
|
if (error.response && error.response.data) {
|
||||||
|
|||||||
@@ -293,19 +293,19 @@ const getMonitorById = async (req, res) => {
|
|||||||
*/
|
*/
|
||||||
const getMonitorsByUserId = async (req, res) => {
|
const getMonitorsByUserId = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const limit = req.body.limit;
|
const limit = req.query.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) => {
|
||||||
|
if (limit) {
|
||||||
if(limit) {
|
|
||||||
// Checks are order oldest -> newest
|
// Checks are order oldest -> newest
|
||||||
const checks = await Check.find({ monitorId: monitor._id }).sort({
|
const checks = await Check.find({ monitorId: monitor._id })
|
||||||
createdAt: 1,
|
.sort({
|
||||||
}).limit(limit);;
|
createdAt: 1,
|
||||||
|
})
|
||||||
|
.limit(limit);
|
||||||
return { ...monitor.toObject(), checks };
|
return { ...monitor.toObject(), checks };
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Checks are order oldest -> newest
|
// Checks are order oldest -> newest
|
||||||
const checks = await Check.find({ monitorId: monitor._id }).sort({
|
const checks = await Check.find({ monitorId: monitor._id }).sort({
|
||||||
|
|||||||
@@ -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?limit", monitorController.getMonitorsByUserId);
|
router.get("/user/:userId", monitorController.getMonitorsByUserId);
|
||||||
|
|
||||||
router.post("/", monitorController.createMonitor);
|
router.post("/", monitorController.createMonitor);
|
||||||
router.post(
|
router.post(
|
||||||
|
|||||||
Reference in new issue
Block a user