diff options
author | 2021-08-16 23:13:06 +0530 | |
---|---|---|
committer | 2021-08-16 23:13:06 +0530 | |
commit | bbed06e2ba255199703343625129712ef7707697 (patch) | |
tree | 19a525fbd1d621a6e561b1a687195269e54f43d5 /src/internal-server/app/Controllers/Http/WorkspaceController.js | |
parent | chore: update outdated node_modules (#1807) (diff) | |
download | ferdium-app-bbed06e2ba255199703343625129712ef7707697.tar.gz ferdium-app-bbed06e2ba255199703343625129712ef7707697.tar.zst ferdium-app-bbed06e2ba255199703343625129712ef7707697.zip |
Revert "chore: update outdated node_modules (#1807)"
This reverts commit 26a9dba22236bc22a7612107630282cfe02d20e0.
Diffstat (limited to 'src/internal-server/app/Controllers/Http/WorkspaceController.js')
-rw-r--r-- | src/internal-server/app/Controllers/Http/WorkspaceController.js | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/src/internal-server/app/Controllers/Http/WorkspaceController.js b/src/internal-server/app/Controllers/Http/WorkspaceController.js index f1a5ddf2b..4189fbcdd 100644 --- a/src/internal-server/app/Controllers/Http/WorkspaceController.js +++ b/src/internal-server/app/Controllers/Http/WorkspaceController.js | |||
@@ -1,11 +1,16 @@ | |||
1 | const Workspace = use('App/Models/Workspace'); | 1 | const Workspace = use('App/Models/Workspace'); |
2 | const { validateAll } = use('Validator'); | 2 | const { |
3 | validateAll, | ||
4 | } = use('Validator'); | ||
3 | 5 | ||
4 | const { v4: uuid } = require('uuid'); | 6 | const uuid = require('uuid/v4'); |
5 | 7 | ||
6 | class WorkspaceController { | 8 | class WorkspaceController { |
7 | // Create a new workspace for user | 9 | // Create a new workspace for user |
8 | async create({ request, response }) { | 10 | async create({ |
11 | request, | ||
12 | response, | ||
13 | }) { | ||
9 | // Validate user input | 14 | // Validate user input |
10 | const validation = await validateAll(request.all(), { | 15 | const validation = await validateAll(request.all(), { |
11 | name: 'required', | 16 | name: 'required', |
@@ -24,10 +29,7 @@ class WorkspaceController { | |||
24 | let workspaceId; | 29 | let workspaceId; |
25 | do { | 30 | do { |
26 | workspaceId = uuid(); | 31 | workspaceId = uuid(); |
27 | } while ( | 32 | } while ((await Workspace.query().where('workspaceId', workspaceId).fetch()).rows.length > 0); // eslint-disable-line no-await-in-loop |
28 | (await Workspace.query().where('workspaceId', workspaceId).fetch()).rows | ||
29 | .length > 0 | ||
30 | ); // eslint-disable-line no-await-in-loop | ||
31 | 33 | ||
32 | const order = (await Workspace.all()).rows.length; | 34 | const order = (await Workspace.all()).rows.length; |
33 | 35 | ||
@@ -48,7 +50,11 @@ class WorkspaceController { | |||
48 | }); | 50 | }); |
49 | } | 51 | } |
50 | 52 | ||
51 | async edit({ request, response, params }) { | 53 | async edit({ |
54 | request, | ||
55 | response, | ||
56 | params, | ||
57 | }) { | ||
52 | // Validate user input | 58 | // Validate user input |
53 | const validation = await validateAll(request.all(), { | 59 | const validation = await validateAll(request.all(), { |
54 | name: 'required', | 60 | name: 'required', |
@@ -63,19 +69,20 @@ class WorkspaceController { | |||
63 | } | 69 | } |
64 | 70 | ||
65 | const data = request.all(); | 71 | const data = request.all(); |
66 | const { id } = params; | 72 | const { |
73 | id, | ||
74 | } = params; | ||
67 | 75 | ||
68 | // Update data in database | 76 | // Update data in database |
69 | await Workspace.query() | 77 | await (Workspace.query() |
70 | .where('workspaceId', id) | 78 | .where('workspaceId', id)).update({ |
71 | .update({ | 79 | name: data.name, |
72 | name: data.name, | 80 | services: JSON.stringify(data.services), |
73 | services: JSON.stringify(data.services), | 81 | }); |
74 | }); | ||
75 | 82 | ||
76 | // Get updated row | 83 | // Get updated row |
77 | const workspace = (await Workspace.query().where('workspaceId', id).fetch()) | 84 | const workspace = (await Workspace.query() |
78 | .rows[0]; | 85 | .where('workspaceId', id).fetch()).rows[0]; |
79 | 86 | ||
80 | return response.send({ | 87 | return response.send({ |
81 | id: workspace.workspaceId, | 88 | id: workspace.workspaceId, |
@@ -104,10 +111,13 @@ class WorkspaceController { | |||
104 | }); | 111 | }); |
105 | } | 112 | } |
106 | 113 | ||
107 | const { id } = params; | 114 | const { |
115 | id, | ||
116 | } = params; | ||
108 | 117 | ||
109 | // Update data in database | 118 | // Update data in database |
110 | await Workspace.query().where('workspaceId', id).delete(); | 119 | await (Workspace.query() |
120 | .where('workspaceId', id)).delete(); | ||
111 | 121 | ||
112 | return response.send({ | 122 | return response.send({ |
113 | message: 'Successfully deleted workspace', | 123 | message: 'Successfully deleted workspace', |
@@ -115,7 +125,9 @@ class WorkspaceController { | |||
115 | } | 125 | } |
116 | 126 | ||
117 | // List all workspaces a user has created | 127 | // List all workspaces a user has created |
118 | async list({ response }) { | 128 | async list({ |
129 | response, | ||
130 | }) { | ||
119 | const workspaces = (await Workspace.all()).rows; | 131 | const workspaces = (await Workspace.all()).rows; |
120 | // Convert to array with all data Franz wants | 132 | // Convert to array with all data Franz wants |
121 | let workspacesArray = []; | 133 | let workspacesArray = []; |
@@ -124,10 +136,7 @@ class WorkspaceController { | |||
124 | id: workspace.workspaceId, | 136 | id: workspace.workspaceId, |
125 | name: workspace.name, | 137 | name: workspace.name, |
126 | order: workspace.order, | 138 | order: workspace.order, |
127 | services: | 139 | services: typeof workspace.services === 'string' ? JSON.parse(workspace.services) : workspace.services, |
128 | typeof workspace.services === 'string' | ||
129 | ? JSON.parse(workspace.services) | ||
130 | : workspace.services, | ||
131 | userId: 1, | 140 | userId: 1, |
132 | })); | 141 | })); |
133 | } | 142 | } |