@@ -89,34 +89,22 @@ const listDeployments: AsyncTypedHandler<
8989 res . status ( 200 ) . json ( data ) ;
9090} ;
9191
92- const getDeployment : AsyncTypedHandler <
93- "/v1/workspaces/{workspaceId}/deployments/{deploymentId}" ,
94- "get"
95- > = async ( req , res ) => {
96- const { workspaceId, deploymentId } = req . params ;
97-
98- const dep = await db . query . deployment . findFirst ( {
99- where : and (
100- eq ( schema . deployment . id , deploymentId ) ,
101- eq ( schema . deployment . workspaceId , workspaceId ) ,
102- ) ,
103- } ) ;
104-
105- if ( dep == null ) throw new ApiError ( "Deployment not found" , 404 ) ;
106-
92+ const getDeploymentWithVariablesAndSystems = async (
93+ dep : typeof schema . deployment . $inferSelect ,
94+ ) => {
10795 const systemRows = await db
10896 . select ( { system : schema . system } )
10997 . from ( schema . systemDeployment )
11098 . innerJoin (
11199 schema . system ,
112100 eq ( schema . systemDeployment . systemId , schema . system . id ) ,
113101 )
114- . where ( eq ( schema . systemDeployment . deploymentId , deploymentId ) ) ;
102+ . where ( eq ( schema . systemDeployment . deploymentId , dep . id ) ) ;
115103
116104 const variables = await db
117105 . select ( )
118106 . from ( schema . deploymentVariable )
119- . where ( eq ( schema . deploymentVariable . deploymentId , deploymentId ) ) ;
107+ . where ( eq ( schema . deploymentVariable . deploymentId , dep . id ) ) ;
120108
121109 const variableIds = variables . map ( ( v ) => v . id ) ;
122110 const variableValues =
@@ -142,7 +130,7 @@ const getDeployment: AsyncTypedHandler<
142130 valuesByVariableId . set ( val . deploymentVariableId , arr ) ;
143131 }
144132
145- res . status ( 200 ) . json ( {
133+ return {
146134 deployment : formatDeployment ( dep ) ,
147135 systems : systemRows . map ( ( r ) => formatSystem ( r . system ) ) ,
148136 variables : variables . map ( ( v ) => ( {
@@ -161,7 +149,43 @@ const getDeployment: AsyncTypedHandler<
161149 resourceSelector : parseSelector ( val . resourceSelector ) ,
162150 } ) ) ,
163151 } ) ) ,
152+ } ;
153+ } ;
154+
155+ const getDeployment : AsyncTypedHandler <
156+ "/v1/workspaces/{workspaceId}/deployments/{deploymentId}" ,
157+ "get"
158+ > = async ( req , res ) => {
159+ const { workspaceId, deploymentId } = req . params ;
160+
161+ const dep = await db . query . deployment . findFirst ( {
162+ where : and (
163+ eq ( schema . deployment . id , deploymentId ) ,
164+ eq ( schema . deployment . workspaceId , workspaceId ) ,
165+ ) ,
164166 } ) ;
167+
168+ if ( dep == null ) throw new ApiError ( "Deployment not found" , 404 ) ;
169+
170+ res . status ( 200 ) . json ( await getDeploymentWithVariablesAndSystems ( dep ) ) ;
171+ } ;
172+
173+ const getDeploymentByName : AsyncTypedHandler <
174+ "/v1/workspaces/{workspaceId}/deployments/name/{name}" ,
175+ "get"
176+ > = async ( req , res ) => {
177+ const { workspaceId, name } = req . params ;
178+
179+ const dep = await db . query . deployment . findFirst ( {
180+ where : and (
181+ eq ( schema . deployment . name , name ) ,
182+ eq ( schema . deployment . workspaceId , workspaceId ) ,
183+ ) ,
184+ } ) ;
185+
186+ if ( dep == null ) throw new ApiError ( "Deployment not found" , 404 ) ;
187+
188+ res . status ( 200 ) . json ( await getDeploymentWithVariablesAndSystems ( dep ) ) ;
165189} ;
166190
167191const postDeployment : AsyncTypedHandler <
@@ -505,6 +529,7 @@ const getDeploymentPlan: AsyncTypedHandler<
505529export const deploymentsRouter = Router ( { mergeParams : true } )
506530 . get ( "/" , asyncHandler ( listDeployments ) )
507531 . post ( "/" , asyncHandler ( postDeployment ) )
532+ . get ( "/name/:name" , asyncHandler ( getDeploymentByName ) )
508533 . get ( "/:deploymentId" , asyncHandler ( getDeployment ) )
509534 . put ( "/:deploymentId" , asyncHandler ( upsertDeployment ) )
510535 . delete ( "/:deploymentId" , asyncHandler ( deleteDeployment ) )
0 commit comments