@@ -144,13 +144,6 @@ const getDefaultRlsForCollection = (collectionName, schema = []) => {
144144
145145const SOCIAL_PROVIDER_KEYS = [ "github" , "google" ] ;
146146
147- /**
148- * Sanitizes authProviders from a project document for safe API responses.
149- * Strips clientSecret fields and replaces them with a boolean hasClientSecret flag.
150- * @param {Object } authProviders - Raw authProviders from the project document
151- * @returns {Object } Sanitized providers keyed by provider name
152- */
153-
154147const sanitizeAuthProviders = ( authProviders = { } ) => {
155148 return SOCIAL_PROVIDER_KEYS . reduce ( ( acc , provider ) => {
156149 const config = authProviders ?. [ provider ] || { } ;
@@ -339,19 +332,14 @@ module.exports.getAllProject = async (req, res) => {
339332
340333 const projectIds = projects . map ( p => p . _id ) ;
341334 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 ] } } // cap to last 100 logs per project
335+ { $match : { projectId : { $in : projectIds } } } ,
336+ { $sort : { timestamp : - 1 } } ,
337+ { $limit : 100 } ,
338+ { $group : {
339+ _id : "$projectId" ,
340+ errorCount : { $sum : { $cond : [ { $gte : [ "$status" , 400 ] } , 1 , 0 ] } } ,
341+ successCount : { $sum : { $cond : [ { $lt : [ "$status" , 400 ] } , 1 , 0 ] } }
342+ }
355343 }
356344 } ,
357345 successCount : {
@@ -432,7 +420,7 @@ module.exports.getSingleProject = async (req, res) => {
432420
433421module . exports . regenerateApiKey = async ( req , res ) => {
434422 try {
435- const { keyType } = req . body ; // 'publishable' or 'secret'
423+ const { keyType } = req . body ;
436424
437425 if ( keyType !== "publishable" && keyType !== "secret" ) {
438426 return res
@@ -817,20 +805,11 @@ return res.status(404).json({ success: false, data: {}, message: `Collection ${c
817805 } ) ;
818806 }
819807
820- // Strip password from fields query param for users collection
821- const safeQuery = { ...req . query } ;
822- if ( collectionName === 'users' && safeQuery . fields ) {
823- safeQuery . fields = safeQuery . fields
824- . split ( ',' )
825- . filter ( f => f . trim ( ) . toLowerCase ( ) !== 'password' )
826- . join ( ',' ) ;
827- }
828-
829- const features = new QueryEngine ( baseQuery , safeQuery )
830- . filter ( )
831- . sort ( )
832- . populate ( )
833- . limitFields ( ) ; // fixes: ?populate= and ?expand= now work
808+ const features = new QueryEngine ( baseQuery , req . query )
809+ . filter ( )
810+ . sort ( )
811+ . limitFields ( ) // fixes: ?fields= and ?meta=false now work
812+ . populate ( ) ; // fixes: ?populate= and ?expand= now work
834813
835814 // Get total before paginating
836815 const total = await features . count ( ) ;
@@ -880,8 +859,6 @@ const features = new QueryEngine(baseQuery, safeQuery)
880859 if ( err ?. statusCode === 400 || err ?. name === 'QueryFilterError' ) {
881860 return res . status ( 400 ) . json ( { success : false , data : { } , message : err . message || "Invalid query filter." } ) ;
882861 }
883- return res . status ( 500 ) . json ( { success : false , data : { } , message : "Failed to fetch data." } ) ;
884- }
885862} ;
886863
887864module . exports . deleteCollection = async ( req , res ) => {
0 commit comments