@@ -313,7 +313,7 @@ const calculateGroupStats = (group) => {
313
313
avgResponseTime :
314
314
checksWithResponseTime . length > 0
315
315
? checksWithResponseTime . reduce ( ( sum , check ) => sum + check . responseTime , 0 ) /
316
- checksWithResponseTime . length
316
+ checksWithResponseTime . length
317
317
: 0 ,
318
318
} ;
319
319
} ;
@@ -372,7 +372,10 @@ const getUptimeDetailsById = async (req) => {
372
372
373
373
const getDistributedUptimeDetailsById = async ( req ) => {
374
374
try {
375
- const { monitorId } = req . params ;
375
+ const { monitorId } = req ?. params ?? { } ;
376
+ if ( typeof monitorId === "undefined" ) {
377
+ throw new Error ( ) ;
378
+ }
376
379
const monitor = await Monitor . findById ( monitorId ) ;
377
380
if ( monitor === null || monitor === undefined ) {
378
381
throw new Error ( this . stringService . dbFindMonitorById ( monitorId ) ) ;
@@ -605,98 +608,98 @@ const getMonitorsByTeamId = async (req) => {
605
608
filteredMonitors : [
606
609
...( filter !== undefined
607
610
? [
608
- {
609
- $match : {
610
- $or : [
611
- { name : { $regex : filter , $options : "i" } } ,
612
- { url : { $regex : filter , $options : "i" } } ,
613
- ] ,
611
+ {
612
+ $match : {
613
+ $or : [
614
+ { name : { $regex : filter , $options : "i" } } ,
615
+ { url : { $regex : filter , $options : "i" } } ,
616
+ ] ,
617
+ } ,
614
618
} ,
615
- } ,
616
- ]
619
+ ]
617
620
: [ ] ) ,
618
621
{ $sort : sort } ,
619
622
{ $skip : skip } ,
620
623
...( rowsPerPage ? [ { $limit : rowsPerPage } ] : [ ] ) ,
621
624
...( limit
622
625
? [
623
- {
624
- $lookup : {
625
- from : "checks" ,
626
- let : { monitorId : "$_id" } ,
627
- pipeline : [
628
- {
629
- $match : {
630
- $expr : { $eq : [ "$monitorId" , "$$monitorId" ] } ,
626
+ {
627
+ $lookup : {
628
+ from : "checks" ,
629
+ let : { monitorId : "$_id" } ,
630
+ pipeline : [
631
+ {
632
+ $match : {
633
+ $expr : { $eq : [ "$monitorId" , "$$monitorId" ] } ,
634
+ } ,
631
635
} ,
632
- } ,
633
- { $sort : { createdAt : - 1 } } ,
634
- ... ( limit ? [ { $limit : limit } ] : [ ] ) ,
635
- ] ,
636
- as : "standardchecks" ,
636
+ { $sort : { createdAt : - 1 } } ,
637
+ ... ( limit ? [ { $limit : limit } ] : [ ] ) ,
638
+ ] ,
639
+ as : "standardchecks" ,
640
+ } ,
637
641
} ,
638
- } ,
639
- ]
642
+ ]
640
643
: [ ] ) ,
641
644
...( limit
642
645
? [
643
- {
644
- $lookup : {
645
- from : "pagespeedchecks" ,
646
- let : { monitorId : "$_id" } ,
647
- pipeline : [
648
- {
649
- $match : {
650
- $expr : { $eq : [ "$monitorId" , "$$monitorId" ] } ,
646
+ {
647
+ $lookup : {
648
+ from : "pagespeedchecks" ,
649
+ let : { monitorId : "$_id" } ,
650
+ pipeline : [
651
+ {
652
+ $match : {
653
+ $expr : { $eq : [ "$monitorId" , "$$monitorId" ] } ,
654
+ } ,
651
655
} ,
652
- } ,
653
- { $sort : { createdAt : - 1 } } ,
654
- ... ( limit ? [ { $limit : limit } ] : [ ] ) ,
655
- ] ,
656
- as : "pagespeedchecks" ,
656
+ { $sort : { createdAt : - 1 } } ,
657
+ ... ( limit ? [ { $limit : limit } ] : [ ] ) ,
658
+ ] ,
659
+ as : "pagespeedchecks" ,
660
+ } ,
657
661
} ,
658
- } ,
659
- ]
662
+ ]
660
663
: [ ] ) ,
661
664
...( limit
662
665
? [
663
- {
664
- $lookup : {
665
- from : "hardwarechecks" ,
666
- let : { monitorId : "$_id" } ,
667
- pipeline : [
668
- {
669
- $match : {
670
- $expr : { $eq : [ "$monitorId" , "$$monitorId" ] } ,
666
+ {
667
+ $lookup : {
668
+ from : "hardwarechecks" ,
669
+ let : { monitorId : "$_id" } ,
670
+ pipeline : [
671
+ {
672
+ $match : {
673
+ $expr : { $eq : [ "$monitorId" , "$$monitorId" ] } ,
674
+ } ,
671
675
} ,
672
- } ,
673
- { $sort : { createdAt : - 1 } } ,
674
- ... ( limit ? [ { $limit : limit } ] : [ ] ) ,
675
- ] ,
676
- as : "hardwarechecks" ,
676
+ { $sort : { createdAt : - 1 } } ,
677
+ ... ( limit ? [ { $limit : limit } ] : [ ] ) ,
678
+ ] ,
679
+ as : "hardwarechecks" ,
680
+ } ,
677
681
} ,
678
- } ,
679
- ]
682
+ ]
680
683
: [ ] ) ,
681
684
...( limit
682
685
? [
683
- {
684
- $lookup : {
685
- from : "distributeduptimechecks" ,
686
- let : { monitorId : "$_id" } ,
687
- pipeline : [
688
- {
689
- $match : {
690
- $expr : { $eq : [ "$monitorId" , "$$monitorId" ] } ,
686
+ {
687
+ $lookup : {
688
+ from : "distributeduptimechecks" ,
689
+ let : { monitorId : "$_id" } ,
690
+ pipeline : [
691
+ {
692
+ $match : {
693
+ $expr : { $eq : [ "$monitorId" , "$$monitorId" ] } ,
694
+ } ,
691
695
} ,
692
- } ,
693
- { $sort : { createdAt : - 1 } } ,
694
- ... ( limit ? [ { $limit : limit } ] : [ ] ) ,
695
- ] ,
696
- as : "distributeduptimechecks" ,
696
+ { $sort : { createdAt : - 1 } } ,
697
+ ... ( limit ? [ { $limit : limit } ] : [ ] ) ,
698
+ ] ,
699
+ as : "distributeduptimechecks" ,
700
+ } ,
697
701
} ,
698
- } ,
699
- ]
702
+ ]
700
703
: [ ] ) ,
701
704
702
705
{
0 commit comments