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 20:51:02 -0500
committerLibravatar Vijay A <vraravam@users.noreply.github.com>2022-05-15 20:51:02 -0500
commitb697c160e64ecb614d96bd89c5572b93d91189a3 (patch)
treecaf616e5db63a5c64e30ea88b538235969964ab1 /src/internal-server/app/Controllers/Http/ServiceController.js
parentUpdate submodules, browserslist data updates and linter fixes [skip ci] (diff)
downloadferdium-app-b697c160e64ecb614d96bd89c5572b93d91189a3.tar.gz
ferdium-app-b697c160e64ecb614d96bd89c5572b93d91189a3.tar.zst
ferdium-app-b697c160e64ecb614d96bd89c5572b93d91189a3.zip
Use DEFAULT_SERVICE_SETTINGS for default values (remove duplication)
Added TODO comments, notes, debug logs.
Diffstat (limited to 'src/internal-server/app/Controllers/Http/ServiceController.js')
-rw-r--r--src/internal-server/app/Controllers/Http/ServiceController.js47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/internal-server/app/Controllers/Http/ServiceController.js b/src/internal-server/app/Controllers/Http/ServiceController.js
index 81c03e5ff..26571323d 100644
--- a/src/internal-server/app/Controllers/Http/ServiceController.js
+++ b/src/internal-server/app/Controllers/Http/ServiceController.js
@@ -3,7 +3,7 @@ const { validateAll } = use('Validator');
3const Env = use('Env'); 3const 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, DEFAULT_SERVICE_SETTINGS } = require('../../../../config');
7const { convertToJSON } = require('../../../../jsUtils'); 7const { convertToJSON } = require('../../../../jsUtils');
8const { API_VERSION } = require('../../../../environment-remote'); 8const { API_VERSION } = require('../../../../environment-remote');
9const moveIcon = require('../../ImageHelper'); 9const moveIcon = require('../../ImageHelper');
@@ -14,8 +14,10 @@ const port = Env.get('PORT');
14class ServiceController { 14class ServiceController {
15 // Create a new service for user 15 // Create a new service for user
16 async create({ request, response }) { 16 async create({ request, response }) {
17 const data = request.all();
18
17 // Validate user input 19 // Validate user input
18 const validation = await validateAll(request.all(), { 20 const validation = await validateAll(data, {
19 name: 'required|string', 21 name: 'required|string',
20 recipeId: 'required', 22 recipeId: 'required',
21 }); 23 });
@@ -27,16 +29,13 @@ class ServiceController {
27 }); 29 });
28 } 30 }
29 31
30 const data = request.all();
31
32 // Get new, unused uuid 32 // Get new, unused uuid
33 let serviceId; 33 let serviceId;
34 do { 34 do {
35 serviceId = uuid(); 35 serviceId = uuid();
36 } while ( 36 } while (
37 // eslint-disable-next-line no-await-in-loop, unicorn/no-await-expression-member 37 // eslint-disable-next-line no-await-in-loop, unicorn/no-await-expression-member
38 (await Service.query().where('serviceId', serviceId).fetch()).rows 38 (await Service.query().where('serviceId', serviceId).fetch()).rows.length > 0
39 .length > 0
40 ); 39 );
41 40
42 await Service.create({ 41 await Service.create({
@@ -46,21 +45,23 @@ class ServiceController {
46 settings: JSON.stringify(data), 45 settings: JSON.stringify(data),
47 }); 46 });
48 47
48 // TODO: Remove duplication
49 return response.send({ 49 return response.send({
50 data: { 50 data: {
51 userId: 1, 51 userId: 1,
52 id: serviceId, 52 id: serviceId,
53 isEnabled: true, 53 isEnabled: DEFAULT_SERVICE_SETTINGS.isEnabled,
54 isNotificationEnabled: true, 54 isNotificationEnabled: DEFAULT_SERVICE_SETTINGS.isNotificationEnabled,
55 isBadgeEnabled: true, 55 isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
56 isMuted: false, 56 isMuted: DEFAULT_SERVICE_SETTINGS.isMuted,
57 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work. 57 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work.
58 spellcheckerLanguage: '', 58 spellcheckerLanguage: '',
59 order: DEFAULT_SERVICE_ORDER, 59 order: DEFAULT_SERVICE_ORDER,
60 customRecipe: false, 60 customRecipe: false,
61 hasCustomIcon: false, 61 hasCustomIcon: DEFAULT_SERVICE_SETTINGS.customIcon,
62 workspaces: [], 62 workspaces: [],
63 iconUrl: null, 63 iconUrl: null,
64 // Overwrite previous default settings with what's obtained from the request
64 ...data, 65 ...data,
65 }, 66 },
66 status: ['created'], 67 status: ['created'],
@@ -75,18 +76,21 @@ class ServiceController {
75 const servicesArray = services.map(service => { 76 const servicesArray = services.map(service => {
76 const settings = convertToJSON(service.settings); 77 const settings = convertToJSON(service.settings);
77 78
79 // TODO: Remove duplication
78 return { 80 return {
79 customRecipe: false, 81 customRecipe: false,
80 hasCustomIcon: false, 82 hasCustomIcon: false,
81 isBadgeEnabled: true, 83 isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
82 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work. 84 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work.
83 isEnabled: true, 85 isEnabled: DEFAULT_SERVICE_SETTINGS.isEnabled,
84 isMuted: false, 86 isMuted: DEFAULT_SERVICE_SETTINGS.isMuted,
85 isNotificationEnabled: true, 87 isNotificationEnabled: DEFAULT_SERVICE_SETTINGS.isNotificationEnabled,
86 order: DEFAULT_SERVICE_ORDER, 88 order: DEFAULT_SERVICE_ORDER,
87 spellcheckerLanguage: '', 89 spellcheckerLanguage: '',
88 workspaces: [], 90 workspaces: [],
91 // Overwrite previous default settings with what's obtained from the db
89 ...settings, 92 ...settings,
93 // Overwrite even after the spread operator with specific values
90 iconUrl: settings.iconId 94 iconUrl: settings.iconId
91 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}` 95 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}`
92 : null, 96 : null,
@@ -217,18 +221,21 @@ class ServiceController {
217 const servicesArray = services.map(service => { 221 const servicesArray = services.map(service => {
218 const settings = convertToJSON(service.settings); 222 const settings = convertToJSON(service.settings);
219 223
224 // TODO: Remove duplication
220 return { 225 return {
221 customRecipe: false, 226 customRecipe: false,
222 hasCustomIcon: false, 227 hasCustomIcon: DEFAULT_SERVICE_SETTINGS.customIcon,
223 isBadgeEnabled: true, 228 isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
224 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work. 229 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work.
225 isEnabled: true, 230 isEnabled: DEFAULT_SERVICE_SETTINGS.isEnabled,
226 isMuted: false, 231 isMuted: DEFAULT_SERVICE_SETTINGS.isMuted,
227 isNotificationEnabled: true, 232 isNotificationEnabled: DEFAULT_SERVICE_SETTINGS.isNotificationEnabled,
228 order: DEFAULT_SERVICE_ORDER, 233 order: DEFAULT_SERVICE_ORDER,
229 spellcheckerLanguage: '', 234 spellcheckerLanguage: '',
230 workspaces: [], 235 workspaces: [],
236 // Overwrite previous default settings with what's obtained from the db
231 ...settings, 237 ...settings,
238 // Overwrite even after the spread operator with specific values
232 iconUrl: settings.iconId 239 iconUrl: settings.iconId
233 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}` 240 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}`
234 : null, 241 : null,