diff --git a/modules/worker/back/methods/device/checkUuid.js b/modules/worker/back/methods/device/checkUuid.js deleted file mode 100644 index 73c6cb57c..000000000 --- a/modules/worker/back/methods/device/checkUuid.js +++ /dev/null @@ -1,61 +0,0 @@ -/* -Author : Enrique Blasco BLanquer -Date: 27 de mayo de 2019 -*/ -module.exports = Self => { - Self.remoteMethodCtx('checkUuid', { - description: 'Check UUID from user', - accessType: 'WRITE', - accepts: [{ - arg: 'data', - type: 'object', - required: true, - description: 'uuid,model', - http: {source: 'body'} - }], - returns: [{ - type: 'Object', - root: true - }], - http: { - path: `/checkUuid`, - verb: 'POST' - } - }); - - Self.checkUuid = async(ctx, data) => { - const myUserId = ctx.req.accessToken.userId; - // 1 Check is a registered user with a uuid - let deviceUser = await Self.findOne({where: {userFk: myUserId, sn: data.uuid}}); - - if (deviceUser != null) - return {'state': true, 'mng': ''}; - else { - // 2 If it does not exist it can be for two reasons: - // 2.1 It is the first time that the application enters so we have to register a new user associated with the user - // 2.2 Has the user associated with a different uuid, so we deny access. - - let device = await Self.findOne({where: {userFk: myUserId}}); - if (device != null) { - // The device is already registered by another user, access is denied - return {'state': false, 'mng': 'Ya estas regisgtrado en otro dispositivo, contacta con los dioses de informática.'}; - } else { - // Check that the device is free - let aDevice = await Self.findOne({where: {sn: data.uuid}}); - if (aDevice != null) - return {'state': false, 'mng': 'El dispositivo esta siendo usado por otro usuario'}; - else { - // It's the first time you access the application, insert - /* await Self.rawSql('INSERT INTO vn2008.device (sn, model) VALUES (?,?);', [data.uuid, data.model]);*/ - await Self.create({ - sn: data.uuid, - model: data.model, - userFk: myUserId - }); - - return {'state': true, 'mng': 'Nuevo dispositivo registrado'}; - } - } - } - }; -}; diff --git a/modules/worker/back/methods/device/specs/checkUuid.spec.js b/modules/worker/back/methods/device/specs/checkUuid.spec.js deleted file mode 100644 index c2784809c..000000000 --- a/modules/worker/back/methods/device/specs/checkUuid.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -const app = require('vn-loopback/server/server'); - -describe('device checkUuid()', () => { - it('should return an state equal to false', async() => { - let ctx = {req: {accessToken: {userId: 9}}}; - let data = {'uuid': '123', 'model': 'ihpne kike molon'}; - let result = await app.models.Device.checkUuid(ctx, data); - - expect(result.name).toBeFalsy(); - }); -}); diff --git a/modules/worker/back/models/device.js b/modules/worker/back/models/device.js index ada0ba33b..cda7a958f 100644 --- a/modules/worker/back/models/device.js +++ b/modules/worker/back/models/device.js @@ -1,8 +1,6 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - require('../methods/device/checkUuid')(Self); - Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') return new UserError(``);