@@ -66,29 +66,40 @@ class WorkspaceController {
6666 } ) ;
6767 }
6868
69- const data = request . all ( ) ;
69+ const toUpdate = request . all ( ) ;
7070 const { id } = params ;
71+ const { name, services, iconUrl } = toUpdate ;
7172
7273 // Update data in database
7374 await Workspace . query ( )
7475 . where ( 'workspaceId' , id )
7576 . update ( {
76- name : data . name ,
77- services : JSON . stringify ( data . services ) ,
77+ name,
78+ services : JSON . stringify ( services ) ,
79+ data : JSON . stringify ( { iconUrl } ) ,
7880 } ) ;
7981
8082 // Get updated row
8183 const workspaceQuery = await Workspace . query ( )
8284 . where ( 'workspaceId' , id )
8385 . fetch ( ) ;
8486 const workspace = workspaceQuery . rows [ 0 ] ;
85-
87+ let data = { } ;
88+ try {
89+ data = JSON . parse ( workspace . data ) ;
90+ } catch ( error ) {
91+ console . warn (
92+ `[WorkspaceController] edit ${ workspace . workspaceId } . Error parsing data JSON` ,
93+ error ,
94+ ) ;
95+ }
8696 return response . send ( {
8797 id : workspace . workspaceId ,
8898 name : data . name ,
8999 order : workspace . order ,
90100 services : data . services ,
91101 userId : 1 ,
102+ iconUrl : data ?. iconUrl || '' ,
92103 } ) ;
93104 }
94105
@@ -122,13 +133,25 @@ class WorkspaceController {
122133 // Convert to array with all data Franz wants
123134 let workspacesArray = [ ] ;
124135 if ( workspaces ) {
125- workspacesArray = workspaces . map ( workspace => ( {
126- id : workspace . workspaceId ,
127- name : workspace . name ,
128- order : workspace . order ,
129- services : convertToJSON ( workspace . services ) ,
130- userId : 1 ,
131- } ) ) ;
136+ workspacesArray = workspaces . map ( workspace => {
137+ let data = { } ;
138+ try {
139+ data = JSON . parse ( workspace . data ) ;
140+ } catch ( error ) {
141+ console . warn (
142+ `[WorkspaceController] list ${ workspace . workspaceId } . Error parsing data JSON` ,
143+ error ,
144+ ) ;
145+ }
146+ return {
147+ id : workspace . workspaceId ,
148+ name : workspace . name ,
149+ iconUrl : data ?. iconUrl || '' ,
150+ order : workspace . order ,
151+ services : convertToJSON ( workspace . services ) ,
152+ userId : 1 ,
153+ } ;
154+ } ) ;
132155 }
133156
134157 return response . send ( workspacesArray ) ;
0 commit comments