@@ -338,30 +338,30 @@ module.exports.getAllProject = async (req, res) => {
338338 . lean ( ) ;
339339
340340 const projectIds = projects . map ( p => p . _id ) ;
341- const recentLogs = await Log . aggregate ( [
342- { $match : { projectId : { $in : projectIds } } } ,
343- { $sort : { timestamp : - 1 } } ,
344- {
345- $group : {
346- _id : "$projectId" ,
347- logs : { $topN : { n : 100 , sortBy : { timestamp : - 1 } , output : { status : "$status" } } }
348- }
349- } ,
350- {
351- $project : {
352- errorCount : {
353- $size : {
354- $filter : { input : "$logs" , as : "l" , cond : { $gte : [ "$$l.status" , 400 ] } }
341+ const recentLogs = await Log . aggregate ( [
342+ { $match : { projectId : { $in : projectIds } } } ,
343+ { $sort : { timestamp : - 1 } } ,
344+ {
345+ $group : {
346+ _id : "$projectId" ,
347+ logs : { $topN : { n : 100 , sortBy : { timestamp : - 1 } , output : { status : "$status" } } }
355348 }
356349 } ,
357- successCount : {
358- $size : {
359- $filter : { input : "$logs" , as : "l" , cond : { $lt : [ "$$l.status" , 400 ] } }
350+ {
351+ $project : {
352+ errorCount : {
353+ $size : {
354+ $filter : { input : "$logs" , as : "l" , cond : { $gte : [ "$$l.status" , 400 ] } }
355+ }
356+ } ,
357+ successCount : {
358+ $size : {
359+ $filter : { input : "$logs" , as : "l" , cond : { $lt : [ "$$l.status" , 400 ] } }
360+ }
361+ }
360362 }
361363 }
362- }
363- }
364- ] ) ;
364+ ] ) ;
365365
366366 const logsMap = recentLogs . reduce ( ( acc , log ) => {
367367 acc [ log . _id . toString ( ) ] = log ;
0 commit comments