@@ -11,6 +11,7 @@ import {
1111 enqueueReleaseTargetsForDeployment ,
1212} from "@ctrlplane/db/reconcilers" ;
1313import * as schema from "@ctrlplane/db/schema" ;
14+ import { getClientFor } from "@ctrlplane/workspace-engine-sdk" ;
1415
1516// 1 hour
1617
@@ -66,54 +67,25 @@ const listDeployments: AsyncTypedHandler<
6667 const { workspaceId } = req . params ;
6768 const limit = req . query . limit ?? 50 ;
6869 const offset = req . query . offset ?? 0 ;
70+ const cel = req . query . cel ;
71+
72+ const { data, error, response } = await getClientFor ( ) . GET (
73+ "/v1/workspaces/{workspaceId}/deployments" ,
74+ {
75+ params : {
76+ path : { workspaceId } ,
77+ query : { limit, offset, cel } ,
78+ } ,
79+ } ,
80+ ) ;
6981
70- const [ countResult ] = await db
71- . select ( { total : count ( ) } )
72- . from ( schema . deployment )
73- . where ( eq ( schema . deployment . workspaceId , workspaceId ) ) ;
74-
75- const total = countResult ?. total ?? 0 ;
76-
77- const deployments = await db
78- . select ( )
79- . from ( schema . deployment )
80- . where ( eq ( schema . deployment . workspaceId , workspaceId ) )
81- . limit ( limit )
82- . offset ( offset ) ;
83-
84- const deploymentIds = deployments . map ( ( d ) => d . id ) ;
85-
86- const systemLinks =
87- deploymentIds . length > 0
88- ? await db
89- . select ( {
90- deploymentId : schema . systemDeployment . deploymentId ,
91- system : schema . system ,
92- } )
93- . from ( schema . systemDeployment )
94- . innerJoin (
95- schema . system ,
96- eq ( schema . systemDeployment . systemId , schema . system . id ) ,
97- )
98- . where ( inArray ( schema . systemDeployment . deploymentId , deploymentIds ) )
99- : [ ] ;
100-
101- const systemsByDeploymentId = new Map <
102- string ,
103- ( typeof schema . system . $inferSelect ) [ ]
104- > ( ) ;
105- for ( const link of systemLinks ) {
106- const arr = systemsByDeploymentId . get ( link . deploymentId ) ?? [ ] ;
107- arr . push ( link . system ) ;
108- systemsByDeploymentId . set ( link . deploymentId , arr ) ;
109- }
110-
111- const items = deployments . map ( ( dep ) => ( {
112- deployment : formatDeployment ( dep ) ,
113- systems : ( systemsByDeploymentId . get ( dep . id ) ?? [ ] ) . map ( formatSystem ) ,
114- } ) ) ;
82+ if ( error != null )
83+ throw new ApiError (
84+ error . error ?? "Failed to list deployments" ,
85+ response . status >= 400 && response . status < 500 ? response . status : 502 ,
86+ ) ;
11587
116- res . status ( 200 ) . json ( { items , total , limit , offset } ) ;
88+ res . status ( 200 ) . json ( data ) ;
11789} ;
11890
11991const getDeployment : AsyncTypedHandler <
0 commit comments