#1711 Eliminar referencias al esquema vn2008

This commit is contained in:
Bernat 2019-11-21 09:08:43 +01:00
parent 525e115781
commit d1dfa126c0
3 changed files with 0 additions and 74 deletions

View File

@ -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'};
}
}
}
};
};

View File

@ -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();
});
});

View File

@ -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(``);