Skip to content

Commit

Permalink
feat: persist iconUrl to internal-server
Browse files Browse the repository at this point in the history
  • Loading branch information
orgrimarr authored and vraravam committed Feb 13, 2024
1 parent 9766e3f commit af26759
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/features/workspaces/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const workspaceApi = {
const url = `${apiBase()}/workspace/${workspace.id}`;
const options = {
method: 'PUT',
body: JSON.stringify(pick(workspace, ['name', 'services'])),
body: JSON.stringify(pick(workspace, ['name', 'services', 'iconUrl'])),
};
debug('updateWorkspace UPDATE', url, options);
const result = await sendAuthRequest(url, options);
Expand Down
45 changes: 34 additions & 11 deletions src/internal-server/app/Controllers/Http/WorkspaceController.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,40 @@ class WorkspaceController {
});
}

const data = request.all();
const toUpdate = request.all();
const { id } = params;
const { name, services, iconUrl } = toUpdate;

// Update data in database
await Workspace.query()
.where('workspaceId', id)
.update({
name: data.name,
services: JSON.stringify(data.services),
name,
services: JSON.stringify(services),
data: JSON.stringify({ iconUrl }),
});

// Get updated row
const workspaceQuery = await Workspace.query()
.where('workspaceId', id)
.fetch();
const workspace = workspaceQuery.rows[0];

let data = {};
try {
data = JSON.parse(workspace.data);
} catch (error) {
console.warn(
`[WorkspaceController] edit ${workspace.workspaceId}. Error parsing data JSON`,
error,
);
}
return response.send({
id: workspace.workspaceId,
name: data.name,
order: workspace.order,
services: data.services,
userId: 1,
iconUrl: data?.iconUrl || '',
});
}

Expand Down Expand Up @@ -122,13 +133,25 @@ class WorkspaceController {
// Convert to array with all data Franz wants
let workspacesArray = [];
if (workspaces) {
workspacesArray = workspaces.map(workspace => ({
id: workspace.workspaceId,
name: workspace.name,
order: workspace.order,
services: convertToJSON(workspace.services),
userId: 1,
}));
workspacesArray = workspaces.map(workspace => {
let data = {};
try {
data = JSON.parse(workspace.data);
} catch (error) {
console.warn(
`[WorkspaceController] list ${workspace.workspaceId}. Error parsing data JSON`,
error,
);
}
return {
id: workspace.workspaceId,
name: workspace.name,
iconUrl: data?.iconUrl || '',
order: workspace.order,
services: convertToJSON(workspace.services),
userId: 1,
};
});
}

return response.send(workspacesArray);
Expand Down

0 comments on commit af26759

Please sign in to comment.