diff options
author | 2022-05-15 01:44:18 -0500 | |
---|---|---|
committer | 2022-05-15 19:05:55 -0500 | |
commit | 082b64b6c40fcab3ecf303f53ce83e7753894a32 (patch) | |
tree | 92626869949cc671effce89cfbcd52092243de5c /src/internal-server/app/Controllers/Http/UserController.js | |
parent | fix: revert "Typescript conversion" (#153) (diff) | |
download | ferdium-app-082b64b6c40fcab3ecf303f53ce83e7753894a32.tar.gz ferdium-app-082b64b6c40fcab3ecf303f53ce83e7753894a32.tar.zst ferdium-app-082b64b6c40fcab3ecf303f53ce83e7753894a32.zip |
Extract utility functions for JSON parsing
Diffstat (limited to 'src/internal-server/app/Controllers/Http/UserController.js')
-rw-r--r-- | src/internal-server/app/Controllers/Http/UserController.js | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/src/internal-server/app/Controllers/Http/UserController.js b/src/internal-server/app/Controllers/Http/UserController.js index 6bd4f85a7..fb1a19db6 100644 --- a/src/internal-server/app/Controllers/Http/UserController.js +++ b/src/internal-server/app/Controllers/Http/UserController.js | |||
@@ -9,6 +9,7 @@ const fetch = require('node-fetch'); | |||
9 | const { v4: uuid } = require('uuid'); | 9 | const { v4: uuid } = require('uuid'); |
10 | const crypto = require('crypto'); | 10 | const crypto = require('crypto'); |
11 | const { DEFAULT_APP_SETTINGS } = require('../../../../config'); | 11 | const { DEFAULT_APP_SETTINGS } = require('../../../../config'); |
12 | const { convertToJSON } = require('../../../../jsUtils'); | ||
12 | const { API_VERSION } = require('../../../../environment-remote'); | 13 | const { API_VERSION } = require('../../../../environment-remote'); |
13 | const { default: userAgent } = require('../../../../helpers/userAgent-helpers'); | 14 | const { default: userAgent } = require('../../../../helpers/userAgent-helpers'); |
14 | 15 | ||
@@ -87,10 +88,7 @@ class UserController { | |||
87 | async me({ response }) { | 88 | async me({ response }) { |
88 | const user = await User.find(1); | 89 | const user = await User.find(1); |
89 | 90 | ||
90 | const settings = | 91 | const settings = convertToJSON(user.settings); |
91 | typeof user.settings === 'string' | ||
92 | ? JSON.parse(user.settings) | ||
93 | : user.settings; | ||
94 | 92 | ||
95 | return response.send({ | 93 | return response.send({ |
96 | ...DEFAULT_USER_DATA, | 94 | ...DEFAULT_USER_DATA, |
@@ -101,10 +99,7 @@ class UserController { | |||
101 | async updateMe({ request, response }) { | 99 | async updateMe({ request, response }) { |
102 | const user = await User.find(1); | 100 | const user = await User.find(1); |
103 | 101 | ||
104 | let settings = user.settings || {}; | 102 | const settings = convertToJSON(user.settings || {}); |
105 | if (typeof settings === 'string') { | ||
106 | settings = JSON.parse(settings); | ||
107 | } | ||
108 | 103 | ||
109 | const newSettings = { | 104 | const newSettings = { |
110 | ...settings, | 105 | ...settings, |
@@ -304,12 +299,8 @@ class UserController { | |||
304 | .rows.length > 0 | 299 | .rows.length > 0 |
305 | ); | 300 | ); |
306 | 301 | ||
307 | if ( | 302 | if (workspace.services) { |
308 | workspace.services && | 303 | workspace.services = convertToJSON(workspace.services); |
309 | typeof workspace.services === 'string' && | ||
310 | workspace.services.length > 0 | ||
311 | ) { | ||
312 | workspace.services = JSON.parse(workspace.services); | ||
313 | } | 304 | } |
314 | const services = | 305 | const services = |
315 | workspace.services && typeof workspace.services === 'object' | 306 | workspace.services && typeof workspace.services === 'object' |
@@ -317,12 +308,8 @@ class UserController { | |||
317 | oldServiceId => serviceIdTranslation[oldServiceId], | 308 | oldServiceId => serviceIdTranslation[oldServiceId], |
318 | ) | 309 | ) |
319 | : []; | 310 | : []; |
320 | if ( | 311 | if (workspace.data) { |
321 | workspace.data && | 312 | workspace.data = convertToJSON(workspace.data); |
322 | typeof workspace.data === 'string' && | ||
323 | workspace.data.length > 0 | ||
324 | ) { | ||
325 | workspace.data = JSON.parse(workspace.data); | ||
326 | } | 313 | } |
327 | 314 | ||
328 | await Workspace.create({ | 315 | await Workspace.create({ |
@@ -347,12 +334,8 @@ class UserController { | |||
347 | // store the old serviceId as the key for future lookup | 334 | // store the old serviceId as the key for future lookup |
348 | serviceIdTranslation[service.serviceId] = newServiceId; | 335 | serviceIdTranslation[service.serviceId] = newServiceId; |
349 | 336 | ||
350 | if ( | 337 | if (service.settings) { |
351 | service.settings && | 338 | service.settings = convertToJSON(service.settings); |
352 | typeof service.settings === 'string' && | ||
353 | service.settings.length > 0 | ||
354 | ) { | ||
355 | service.settings = JSON.parse(service.settings); | ||
356 | } | 339 | } |
357 | 340 | ||
358 | await Service.create({ | 341 | await Service.create({ |