aboutsummaryrefslogtreecommitdiffstats
path: root/src/internal-server/app/Controllers/Http/ServiceController.js
diff options
context:
space:
mode:
authorLibravatar Vijay A <vraravam@users.noreply.github.com>2022-05-15 01:44:18 -0500
committerLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-05-15 19:05:55 -0500
commit082b64b6c40fcab3ecf303f53ce83e7753894a32 (patch)
tree92626869949cc671effce89cfbcd52092243de5c /src/internal-server/app/Controllers/Http/ServiceController.js
parentfix: revert "Typescript conversion" (#153) (diff)
downloadferdium-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/ServiceController.js')
-rw-r--r--src/internal-server/app/Controllers/Http/ServiceController.js26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/internal-server/app/Controllers/Http/ServiceController.js b/src/internal-server/app/Controllers/Http/ServiceController.js
index f2f6e7028..81c03e5ff 100644
--- a/src/internal-server/app/Controllers/Http/ServiceController.js
+++ b/src/internal-server/app/Controllers/Http/ServiceController.js
@@ -4,6 +4,7 @@ const Env = use('Env');
4 4
5const { v4: uuid } = require('uuid'); 5const { v4: uuid } = require('uuid');
6const { LOCAL_HOSTNAME, DEFAULT_SERVICE_ORDER } = require('../../../../config'); 6const { LOCAL_HOSTNAME, DEFAULT_SERVICE_ORDER } = require('../../../../config');
7const { convertToJSON } = require('../../../../jsUtils');
7const { API_VERSION } = require('../../../../environment-remote'); 8const { API_VERSION } = require('../../../../environment-remote');
8const moveIcon = require('../../ImageHelper'); 9const moveIcon = require('../../ImageHelper');
9 10
@@ -72,10 +73,7 @@ class ServiceController {
72 const services = allServices.rows; 73 const services = allServices.rows;
73 // Convert to array with all data Franz wants 74 // Convert to array with all data Franz wants
74 const servicesArray = services.map(service => { 75 const servicesArray = services.map(service => {
75 const settings = 76 const settings = convertToJSON(service.settings);
76 typeof service.settings === 'string'
77 ? JSON.parse(service.settings)
78 : service.settings;
79 77
80 return { 78 return {
81 customRecipe: false, 79 customRecipe: false,
@@ -88,7 +86,7 @@ class ServiceController {
88 order: DEFAULT_SERVICE_ORDER, 86 order: DEFAULT_SERVICE_ORDER,
89 spellcheckerLanguage: '', 87 spellcheckerLanguage: '',
90 workspaces: [], 88 workspaces: [],
91 ...JSON.parse(service.settings), 89 ...settings,
92 iconUrl: settings.iconId 90 iconUrl: settings.iconId
93 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}` 91 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}`
94 : null, 92 : null,
@@ -108,10 +106,7 @@ class ServiceController {
108 const { id } = params; 106 const { id } = params;
109 const serviceQuery = await Service.query().where('serviceId', id).fetch(); 107 const serviceQuery = await Service.query().where('serviceId', id).fetch();
110 const service = serviceQuery.rows[0]; 108 const service = serviceQuery.rows[0];
111 const settings = 109 const settings = convertToJSON(service.settings);
112 typeof service.settings === 'string'
113 ? JSON.parse(service.settings)
114 : service.settings;
115 110
116 const icon = request.file('icon', { 111 const icon = request.file('icon', {
117 types: ['image'], 112 types: ['image'],
@@ -160,9 +155,7 @@ class ServiceController {
160 const serviceData = serviceQuery.rows[0]; 155 const serviceData = serviceQuery.rows[0];
161 156
162 const settings = { 157 const settings = {
163 ...(typeof serviceData.settings === 'string' 158 ...convertToJSON(serviceData.settings),
164 ? JSON.parse(serviceData.settings)
165 : serviceData.settings),
166 ...data, 159 ...data,
167 }; 160 };
168 161
@@ -205,7 +198,7 @@ class ServiceController {
205 const serviceData = serviceQuery.rows[0]; 198 const serviceData = serviceQuery.rows[0];
206 199
207 const settings = { 200 const settings = {
208 ...JSON.parse(serviceData.settings), 201 ...convertToJSON(serviceData.settings),
209 order: data[service], 202 order: data[service],
210 }; 203 };
211 204
@@ -222,10 +215,7 @@ class ServiceController {
222 const services = allServices.rows; 215 const services = allServices.rows;
223 // Convert to array with all data Franz wants 216 // Convert to array with all data Franz wants
224 const servicesArray = services.map(service => { 217 const servicesArray = services.map(service => {
225 const settings = 218 const settings = convertToJSON(service.settings);
226 typeof service.settings === 'string'
227 ? JSON.parse(service.settings)
228 : service.settings;
229 219
230 return { 220 return {
231 customRecipe: false, 221 customRecipe: false,
@@ -238,7 +228,7 @@ class ServiceController {
238 order: DEFAULT_SERVICE_ORDER, 228 order: DEFAULT_SERVICE_ORDER,
239 spellcheckerLanguage: '', 229 spellcheckerLanguage: '',
240 workspaces: [], 230 workspaces: [],
241 ...JSON.parse(service.settings), 231 ...settings,
242 iconUrl: settings.iconId 232 iconUrl: settings.iconId
243 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}` 233 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}`
244 : null, 234 : null,