11import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' ;
22import { validator , schema } from '@ioc:Adonis/Core/Validator' ;
3- import Workspace , { type CustomData } from 'App/Models/Workspace' ;
3+ import Workspace from 'App/Models/Workspace' ;
44import { v4 as uuid } from 'uuid' ;
55
66const createSchema = schema . create ( {
@@ -89,24 +89,14 @@ export default class WorkspaceController {
8989 const data = request . all ( ) ;
9090 const { id } = params ;
9191
92- const currentWorkspace = await Workspace . query ( )
93- . where ( 'workspaceId' , id )
94- . where ( 'userId' , user . id )
95- . firstOrFail ( ) ;
96- const customData : CustomData = JSON . parse ( currentWorkspace . data || '{}' ) ;
97- Object . assign ( customData , {
98- name : data . name ,
99- iconUrl : data . iconUrl ,
100- } ) ;
101-
10292 // Update data in database
10393 await Workspace . query ( )
10494 . where ( 'workspaceId' , id )
10595 . where ( 'userId' , user . id )
10696 . update ( {
10797 name : data . name ,
10898 services : JSON . stringify ( data . services ) ,
109- data : JSON . stringify ( customData ) ,
99+ iconUrl : data . iconUrl ,
110100 } ) ;
111101
112102 // Get updated row
@@ -117,11 +107,10 @@ export default class WorkspaceController {
117107
118108 return response . send ( {
119109 id : workspace . workspaceId ,
120- name : workspace . name ,
110+ name : data . name ,
121111 order : workspace . order ,
122- services : workspace . services ,
112+ services : data . services ,
123113 userId : user . id ,
124- iconUrl : customData . iconUrl ,
125114 } ) ;
126115 }
127116
@@ -177,30 +166,20 @@ export default class WorkspaceController {
177166
178167 const workspaces = await user . related ( 'workspaces' ) . query ( ) ;
179168 // Convert to array with all data Franz wants
180- let workspacesArray : Workspace [ ] = [ ] ;
169+ let workspacesArray : object [ ] = [ ] ;
181170 if ( workspaces ) {
182- workspacesArray = workspaces . map ( ( workspace : Workspace ) => {
183- let data : CustomData = { } ;
184- try {
185- data = JSON . parse ( workspace . data ) ;
186- } catch ( error ) {
187- console . warn (
188- `[WorkspaceController] list ${ workspace . workspaceId } . Error parsing data JSON` ,
189- error ,
190- ) ;
191- }
192- return {
193- id : workspace . workspaceId ,
194- name : workspace . name ,
195- order : workspace . order ,
196- services :
197- typeof workspace . services === 'string'
198- ? JSON . parse ( workspace . services )
199- : workspace . services ,
200- userId : user . id ,
201- iconUrl : data . iconUrl ?? '' ,
202- } ;
203- } ) ;
171+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
172+ workspacesArray = workspaces . map ( ( workspace : any ) => ( {
173+ id : workspace . workspaceId ,
174+ name : workspace . name ,
175+ iconUrl : workspace . iconUrl ,
176+ order : workspace . order ,
177+ services :
178+ typeof workspace . services === 'string'
179+ ? JSON . parse ( workspace . services )
180+ : workspace . services ,
181+ userId : user . id ,
182+ } ) ) ;
204183 }
205184
206185 return response . send ( workspacesArray ) ;
0 commit comments