diff options
author | vantezzen <properly@protonmail.com> | 2019-08-23 10:37:06 +0200 |
---|---|---|
committer | vantezzen <properly@protonmail.com> | 2019-08-23 10:37:06 +0200 |
commit | c9f77d78f7230560be1918325c720132c6b130a5 (patch) | |
tree | 4d36154a4a2b4c3c2746e5f8e6ce2ac4ae79fb7b /app | |
parent | Initial commit (diff) | |
download | ferdium-server-c9f77d78f7230560be1918325c720132c6b130a5.tar.gz ferdium-server-c9f77d78f7230560be1918325c720132c6b130a5.tar.zst ferdium-server-c9f77d78f7230560be1918325c720132c6b130a5.zip |
Use UUID instead of number for service id
Diffstat (limited to 'app')
-rw-r--r-- | app/Controllers/Http/ServiceController.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/app/Controllers/Http/ServiceController.js b/app/Controllers/Http/ServiceController.js index 47a8a6f..0fcbec0 100644 --- a/app/Controllers/Http/ServiceController.js +++ b/app/Controllers/Http/ServiceController.js | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | const User = use('App/Models/User'); | 3 | const User = use('App/Models/User'); |
4 | const Service = use('App/Models/Service'); | 4 | const Service = use('App/Models/Service'); |
5 | const uuid = require('uuid/v4'); | ||
5 | 6 | ||
6 | class ServiceController { | 7 | class ServiceController { |
7 | // Create a new service for user | 8 | // Create a new service for user |
@@ -18,8 +19,15 @@ class ServiceController { | |||
18 | 19 | ||
19 | const data = request.all(); | 20 | const data = request.all(); |
20 | 21 | ||
22 | // Get new, unused uuid | ||
23 | let serviceId; | ||
24 | do { | ||
25 | serviceId = uuid(); | ||
26 | } while((await Service.all()).rows.length > 0) | ||
27 | |||
21 | const service = await Service.create({ | 28 | const service = await Service.create({ |
22 | userId: auth.user.id, | 29 | userId: auth.user.id, |
30 | serviceId, | ||
23 | name: data.name, | 31 | name: data.name, |
24 | recipeId: data.recipeId, | 32 | recipeId: data.recipeId, |
25 | settings: JSON.stringify(data) | 33 | settings: JSON.stringify(data) |
@@ -28,7 +36,7 @@ class ServiceController { | |||
28 | return response.send({ | 36 | return response.send({ |
29 | "data": { | 37 | "data": { |
30 | userId: auth.user.id, | 38 | userId: auth.user.id, |
31 | id: service.id, | 39 | id: serviceId, |
32 | "isEnabled": true, | 40 | "isEnabled": true, |
33 | "isNotificationEnabled": true, | 41 | "isNotificationEnabled": true, |
34 | "isBadgeEnabled": true, | 42 | "isBadgeEnabled": true, |
@@ -74,7 +82,7 @@ class ServiceController { | |||
74 | "workspaces": [], | 82 | "workspaces": [], |
75 | "iconUrl": null, | 83 | "iconUrl": null, |
76 | ...JSON.parse(service.settings), | 84 | ...JSON.parse(service.settings), |
77 | "id": service.id, | 85 | "id": service.serviceId, |
78 | "name": service.name, | 86 | "name": service.name, |
79 | "recipeId": service.recipeId, | 87 | "recipeId": service.recipeId, |
80 | "userId": auth.user.id, | 88 | "userId": auth.user.id, |