@@ -74,16 +74,18 @@ class WorkspaceController {
7474 } ) ;
7575 }
7676
77- const data = request . all ( ) ;
77+ const toUpdate = request . all ( ) ;
7878 const { id } = params ;
79+ const { name, services, iconUrl } = toUpdate ;
7980
8081 // Update data in database
8182 await Workspace . query ( )
8283 . where ( 'workspaceId' , id )
8384 . where ( 'userId' , auth . user . id )
8485 . update ( {
85- name : data . name ,
86- services : JSON . stringify ( data . services ) ,
86+ name : name ,
87+ services : JSON . stringify ( services ) ,
88+ data : JSON . stringify ( { iconUrl } ) ,
8789 } ) ;
8890
8991 // Get updated row
@@ -93,13 +95,24 @@ class WorkspaceController {
9395 . where ( 'userId' , auth . user . id )
9496 . fetch ( )
9597 ) . rows [ 0 ] ;
96-
98+ let data = { } ;
99+ try {
100+ if ( typeof data === 'string' ) {
101+ data = JSON . parse ( workspace . data ) ;
102+ }
103+ } catch ( error ) {
104+ console . warn (
105+ `[WorkspaceController] edit ${ workspace . workspaceId } . Error parsing data JSON` ,
106+ error ,
107+ ) ;
108+ }
97109 return response . send ( {
98110 id : workspace . workspaceId ,
99111 name : data . name ,
100112 order : workspace . order ,
101113 services : data . services ,
102114 userId : auth . user . id ,
115+ iconUrl : data ?. iconUrl || '' ,
103116 } ) ;
104117 }
105118
@@ -153,16 +166,30 @@ class WorkspaceController {
153166 // Convert to array with all data Franz wants
154167 let workspacesArray = [ ] ;
155168 if ( workspaces ) {
156- workspacesArray = workspaces . map ( workspace => ( {
157- id : workspace . workspaceId ,
158- name : workspace . name ,
159- order : workspace . order ,
160- services :
161- typeof workspace . services === 'string'
162- ? JSON . parse ( workspace . services )
163- : workspace . services ,
164- userId : auth . user . id ,
165- } ) ) ;
169+ workspacesArray = workspaces . map ( workspace => {
170+ let data = { } ;
171+ try {
172+ if ( typeof data === 'string' ) {
173+ data = JSON . parse ( workspace . data ) ;
174+ }
175+ } catch ( error ) {
176+ console . warn (
177+ `[WorkspaceController] list ${ workspace . workspaceId } . Error parsing data JSON` ,
178+ error ,
179+ ) ;
180+ }
181+ return {
182+ id : workspace . workspaceId ,
183+ name : workspace . name ,
184+ order : workspace . order ,
185+ services :
186+ typeof workspace . services === 'string'
187+ ? JSON . parse ( workspace . services )
188+ : workspace . services ,
189+ userId : auth . user . id ,
190+ iconUrl : data ?. iconUrl || '' ,
191+ } ;
192+ } ) ;
166193 }
167194
168195 return response . send ( workspacesArray ) ;
0 commit comments