Prechádzať zdrojové kódy

Update StoryService, fix division by zero bug

Daniel Supernault 3 rokov pred
rodič
commit
6ae1ba0a64
1 zmenil súbory, kde vykonal 2 pridanie a 2 odobranie
  1. 2 2
      app/Services/StoryService.php

+ 2 - 2
app/Services/StoryService.php

@@ -121,9 +121,9 @@ class StoryService
 					'sum' => (int) Story::sum('size'),
 					'average' => (int) Story::avg('size')
 				],
-				'avg_spu' => (int) ($total / Story::groupBy('profile_id')->pluck('profile_id')->count()),
+				'avg_spu' => $total ? (int) ($total / Story::groupBy('profile_id')->pluck('profile_id')->count()) : 'N/A',
 				'avg_duration' => (int) floor(Story::avg('duration')),
-				'avg_type' => Story::selectRaw('type, count(id) as count')->groupBy('type')->orderByDesc('count')->first()->type
+				'avg_type' => $total ? Story::selectRaw('type, count(id) as count')->groupBy('type')->orderByDesc('count')->first()->type : 'N/A'
 			];
 		});
 	}