@@ -1040,6 +1040,25 @@ export class HttpDispatcher {
10401040 return rows [ 0 ] ;
10411041 } ;
10421042
1043+ const toEnvironmentDto = ( row : any ) : any => {
1044+ if ( ! row ) return row ;
1045+ return {
1046+ id : row . id ,
1047+ organizationId : row . organization_id ,
1048+ slug : row . slug ,
1049+ displayName : row . display_name ,
1050+ envType : row . env_type ,
1051+ isDefault : row . is_default ?? false ,
1052+ region : row . region ,
1053+ plan : row . plan ,
1054+ status : row . status ,
1055+ createdBy : row . created_by ,
1056+ metadata : row . metadata ,
1057+ createdAt : row . created_at ,
1058+ updatedAt : row . updated_at ,
1059+ } ;
1060+ } ;
1061+
10431062 try {
10441063 // ----- /cloud/drivers ------------------------------------------
10451064 if ( parts . length === 1 && parts [ 0 ] === 'drivers' && m === 'GET' ) {
@@ -1055,7 +1074,7 @@ export class HttpDispatcher {
10551074 if ( query ?. status ) where . status = query . status ;
10561075 let rows = await ql . find ( ENV , Object . keys ( where ) . length ? ( { where } as any ) : undefined ) ;
10571076 if ( rows && ( rows as any ) . value ) rows = ( rows as any ) . value ;
1058- const environments = Array . isArray ( rows ) ? rows : [ ] ;
1077+ const environments = ( Array . isArray ( rows ) ? rows : [ ] ) . map ( toEnvironmentDto ) ;
10591078 return { handled : true , response : this . success ( { environments, total : environments . length } ) } ;
10601079 }
10611080
@@ -1156,7 +1175,7 @@ export class HttpDispatcher {
11561175 updated_at : nowIso ,
11571176 } ) ;
11581177
1159- const environment = await findOne ( ENV , { id : environmentId } ) ;
1178+ const environment = toEnvironmentDto ( await findOne ( ENV , { id : environmentId } ) ) ;
11601179 const database = await findOne ( DB , { id : environmentDatabaseId } ) ;
11611180 const res = this . success ( { environment, database } ) ;
11621181 res . status = 201 ;
@@ -1168,8 +1187,8 @@ export class HttpDispatcher {
11681187 const id = decodeURIComponent ( parts [ 1 ] ) ;
11691188
11701189 if ( m === 'GET' ) {
1171- const environment = await findOne ( ENV , { id } ) ;
1172- if ( ! environment ) return { handled : true , response : this . error ( `Environment '${ id } ' not found` , 404 ) } ;
1190+ const envRow = await findOne ( ENV , { id } ) ;
1191+ if ( ! envRow ) return { handled : true , response : this . error ( `Environment '${ id } ' not found` , 404 ) } ;
11731192 const database = await findOne ( DB , { environment_id : id } ) ;
11741193 const credential = database
11751194 ? await findOne ( CRED , { environment_database_id : database . id , status : 'active' } )
@@ -1187,7 +1206,7 @@ export class HttpDispatcher {
11871206 : undefined ;
11881207 return {
11891208 handled : true ,
1190- response : this . success ( { environment, database, credential : credMeta , membership } ) ,
1209+ response : this . success ( { environment : toEnvironmentDto ( envRow ) , database, credential : credMeta , membership } ) ,
11911210 } ;
11921211 }
11931212
@@ -1200,19 +1219,19 @@ export class HttpDispatcher {
12001219 if ( body ?. metadata !== undefined ) patch . metadata = JSON . stringify ( body . metadata ) ;
12011220 patch . updated_at = new Date ( ) . toISOString ( ) ;
12021221 await ql . update ( ENV , patch , { where : { id } } as any ) ;
1203- const environment = await findOne ( ENV , { id } ) ;
1204- if ( ! environment ) return { handled : true , response : this . error ( `Environment '${ id } ' not found` , 404 ) } ;
1205- return { handled : true , response : this . success ( { environment } ) } ;
1222+ const envRow = await findOne ( ENV , { id } ) ;
1223+ if ( ! envRow ) return { handled : true , response : this . error ( `Environment '${ id } ' not found` , 404 ) } ;
1224+ return { handled : true , response : this . success ( { environment : toEnvironmentDto ( envRow ) } ) } ;
12061225 }
12071226 }
12081227
12091228 // ----- /cloud/environments/:id/activate -----
12101229 if ( parts . length === 3 && parts [ 0 ] === 'environments' && parts [ 2 ] === 'activate' && m === 'POST' ) {
12111230 const id = decodeURIComponent ( parts [ 1 ] ) ;
1212- const environment = await findOne ( ENV , { id } ) ;
1213- if ( ! environment ) return { handled : true , response : this . error ( `Environment '${ id } ' not found` , 404 ) } ;
1231+ const envRow = await findOne ( ENV , { id } ) ;
1232+ if ( ! envRow ) return { handled : true , response : this . error ( `Environment '${ id } ' not found` , 404 ) } ;
12141233 // TODO: persist active_environment_id on the session once session service is wired.
1215- return { handled : true , response : this . success ( { environment, sessionUpdated : false } ) } ;
1234+ return { handled : true , response : this . success ( { environment : toEnvironmentDto ( envRow ) , sessionUpdated : false } ) } ;
12161235 }
12171236
12181237 // ----- /cloud/environments/:id/credentials/rotate -----
0 commit comments