Skip to content

Commit 7106504

Browse files
orgrimarrvraravam
authored andcommitted
feat: persist iconUrl to internal-server
1 parent c66edb9 commit 7106504

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/features/workspaces/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const workspaceApi = {
5151
const url = `${apiBase()}/workspace/${workspace.id}`;
5252
const options = {
5353
method: 'PUT',
54-
body: JSON.stringify(pick(workspace, ['name', 'services'])),
54+
body: JSON.stringify(pick(workspace, ['name', 'services', 'iconUrl'])),
5555
};
5656
debug('updateWorkspace UPDATE', url, options);
5757
const result = await sendAuthRequest(url, options);

src/internal-server/app/Controllers/Http/WorkspaceController.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)