From c9f77d78f7230560be1918325c720132c6b130a5 Mon Sep 17 00:00:00 2001 From: vantezzen Date: Fri, 23 Aug 2019 10:37:06 +0200 Subject: Use UUID instead of number for service id --- app/Controllers/Http/ServiceController.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'app/Controllers/Http/ServiceController.js') 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 @@ const User = use('App/Models/User'); const Service = use('App/Models/Service'); +const uuid = require('uuid/v4'); class ServiceController { // Create a new service for user @@ -18,8 +19,15 @@ class ServiceController { const data = request.all(); + // Get new, unused uuid + let serviceId; + do { + serviceId = uuid(); + } while((await Service.all()).rows.length > 0) + const service = await Service.create({ userId: auth.user.id, + serviceId, name: data.name, recipeId: data.recipeId, settings: JSON.stringify(data) @@ -28,7 +36,7 @@ class ServiceController { return response.send({ "data": { userId: auth.user.id, - id: service.id, + id: serviceId, "isEnabled": true, "isNotificationEnabled": true, "isBadgeEnabled": true, @@ -74,7 +82,7 @@ class ServiceController { "workspaces": [], "iconUrl": null, ...JSON.parse(service.settings), - "id": service.id, + "id": service.serviceId, "name": service.name, "recipeId": service.recipeId, "userId": auth.user.id, -- cgit v1.2.3-54-g00ecf