@@ -41,22 +41,39 @@ export async function GET(request: NextRequest) {
4141 const newConnections = await db . integrationConnection . findMany ( {
4242 where : {
4343 organizationId : orgId ,
44+ status : 'active' ,
4445 provider : {
4546 slug : {
4647 in : CLOUD_PROVIDER_SLUGS ,
4748 } ,
4849 } ,
4950 } ,
50- select : {
51- id : true ,
52- provider : {
53- select : {
54- slug : true ,
55- } ,
51+ include : {
52+ provider : true ,
53+ } ,
54+ } ) ;
55+
56+ // ====================================================================
57+ // Fetch from OLD integration table (Integration) - for backward compat
58+ // ====================================================================
59+ const legacyIntegrations = await db . integration . findMany ( {
60+ where : {
61+ organizationId : orgId ,
62+ integrationId : {
63+ in : CLOUD_PROVIDER_SLUGS ,
5664 } ,
5765 } ,
5866 } ) ;
5967
68+ // Filter out legacy integrations that have been migrated to new platform
69+ const newConnectionSlugs = new Set ( newConnections . map ( ( c ) => c . provider . slug ) ) ;
70+ const activeLegacyIntegrations = legacyIntegrations . filter (
71+ ( i ) => ! newConnectionSlugs . has ( i . integrationId ) ,
72+ ) ;
73+
74+ // ====================================================================
75+ // Fetch findings from NEW platform (IntegrationCheckResult)
76+ // ====================================================================
6077 const newConnectionIds = newConnections . map ( ( c ) => c . id ) ;
6178 const connectionToSlug = Object . fromEntries ( newConnections . map ( ( c ) => [ c . id , c . provider . slug ] ) ) ;
6279
@@ -77,13 +94,12 @@ export async function GET(request: NextRequest) {
7794 const latestRunIds = latestRuns . map ( ( r ) => r . id ) ;
7895 const checkRunMap = Object . fromEntries ( latestRuns . map ( ( cr ) => [ cr . id , cr ] ) ) ;
7996
80- // Fetch only failed results from the latest runs (findings only, no passing results )
97+ // Fetch results only from the latest runs (both passed and failed )
8198 const newResults =
8299 latestRunIds . length > 0
83100 ? await db . integrationCheckResult . findMany ( {
84101 where : {
85102 checkRunId : { in : latestRunIds } ,
86- passed : false ,
87103 } ,
88104 select : {
89105 id : true ,
@@ -93,6 +109,7 @@ export async function GET(request: NextRequest) {
93109 severity : true ,
94110 collectedAt : true ,
95111 checkRunId : true ,
112+ passed : true ,
96113 } ,
97114 orderBy : {
98115 collectedAt : 'desc' ,
@@ -107,33 +124,26 @@ export async function GET(request: NextRequest) {
107124 title : result . title ,
108125 description : result . description ,
109126 remediation : result . remediation ,
110- status : 'failed' ,
127+ status : result . passed ? 'passed' : 'failed' ,
111128 severity : result . severity ,
112129 completedAt : result . collectedAt ,
113130 integration : {
114- integrationId : checkRun
115- ? connectionToSlug [ checkRun . connectionId ] || 'unknown'
116- : 'unknown' ,
131+ integrationId : checkRun ? connectionToSlug [ checkRun . connectionId ] || 'unknown' : 'unknown' ,
117132 } ,
118133 } ;
119134 } ) ;
120135
121136 // ====================================================================
122- // Fetch from OLD integration platform
137+ // Fetch findings from OLD platform (IntegrationResult)
123138 // ====================================================================
124- // Filter out cloud providers that have migrated to new platform
125- const newConnectionSlugs = new Set ( newConnections . map ( ( c ) => c . provider . slug ) ) ;
126- const legacySlugs = CLOUD_PROVIDER_SLUGS . filter ( ( s ) => ! newConnectionSlugs . has ( s ) ) ;
139+ const legacyIntegrationIds = activeLegacyIntegrations . map ( ( i ) => i . id ) ;
127140
128141 const legacyResults =
129- legacySlugs . length > 0
142+ legacyIntegrationIds . length > 0
130143 ? await db . integrationResult . findMany ( {
131144 where : {
132- organizationId : orgId ,
133- integration : {
134- integrationId : {
135- in : legacySlugs ,
136- } ,
145+ integrationId : {
146+ in : legacyIntegrationIds ,
137147 } ,
138148 } ,
139149 select : {
@@ -171,7 +181,7 @@ export async function GET(request: NextRequest) {
171181 } ) ) ;
172182
173183 // ====================================================================
174- // Merge and sort by date
184+ // Merge all findings and sort by date
175185 // ====================================================================
176186 const findings = [ ...newFindings , ...legacyFindings ] . sort ( ( a , b ) => {
177187 const dateA = a . completedAt ? new Date ( a . completedAt ) . getTime ( ) : 0 ;
0 commit comments