diff --git a/db/routines/vn/procedures/workerTimeControl_clockIn.sql b/db/routines/vn/procedures/workerTimeControl_clockIn.sql index 2d790c301..23739a515 100644 --- a/db/routines/vn/procedures/workerTimeControl_clockIn.sql +++ b/db/routines/vn/procedures/workerTimeControl_clockIn.sql @@ -2,21 +2,23 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_clockIn`( vWorkerFk INT, vTimed DATETIME, - vDirection VARCHAR(10) + vDirection VARCHAR(10), + vDevice VARCHAR(255) ) BEGIN /** - * Verifica si el empleado puede fichar - * @param vWorkerFk Identificador del trabajador - * @param vTimed valor de la fichada, IF vTimed IS NULL vTimed = NOW - * @param vDirection solo se pueden pasa los valores del campo - * workerTimeControl.direction ENUM('in', 'out', 'middle') - * @return Si todo es correcto, retorna el número de id la tabla workerTimeControl. - * Si hay algún problema, devuelve el mesaje que se debe mostrar al usuario - * Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá - * fichada a la tabla vn.workerTimeControl - */ - +* Verifica si el empleado puede fichar +* @param vWorkerFk Identificador del trabajador +* @param vTimed Balor de la fichada, IF vTimed IS NULL vTimed = NOW +* @param vDirection Solo se pueden pasa los valores del campo +* workerTimeControl.direction ENUM('in', 'out', 'middle') +* @param vDevice Dispositivo en el que se ha fichado +* @return Si todo es correcto, retorna el número de id la tabla workerTimeControl. +* Si hay algún problema, devuelve el mesaje que se debe mostrar al usuario +* Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá +* fichada a la tabla vn.workerTimeControl +*/ + DECLARE vLastIn DATETIME; DECLARE vLastOut DATETIME; DECLARE vNextIn DATETIME; @@ -269,16 +271,16 @@ BEGIN GROUP BY breakCounter HAVING hasError LIMIT 1; - + IF vIsError THEN SET vErrorCode = 'BREAK_WEEK'; CALL util.throw(vErrorCode); END IF; END IF; - - -- SE PERMITE FICHAR - INSERT INTO workerTimeControl(userFk, timed, direction, `manual`) - VALUES(vWorkerFk, vTimed, vDirection, vIsManual); + + -- Se permite fichar + INSERT INTO workerTimeControl(userFk, timed, direction, device, `manual`) + VALUES(vWorkerFk, vTimed, vDirection, vDevice, vIsManual); SELECT LAST_INSERT_ID() id; diff --git a/db/versions/10853-grayOak/00-firstScript.sql b/db/versions/10853-grayOak/00-firstScript.sql new file mode 100644 index 000000000..4b07ce72d --- /dev/null +++ b/db/versions/10853-grayOak/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.workerTimeControl ADD device varchar(255) DEFAULT NULL NULL COMMENT 'Dispositivo en el que se ha fichado' AFTER `order`; \ No newline at end of file diff --git a/db/versions/10853-grayOak/00-secondScript.sql b/db/versions/10853-grayOak/00-secondScript.sql new file mode 100644 index 000000000..43a98b837 --- /dev/null +++ b/db/versions/10853-grayOak/00-secondScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.workerTimeControl CHANGE direction direction enum('in','out','middle') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'middle' NULL AFTER timed; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5555ef8b0..0a0865bdf 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -333,7 +333,7 @@ "It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}", "This claim has been updated": "La reclamación con Id: {{claimId}}, ha sido actualizada", "This user does not have an assigned tablet": "Este usuario no tiene tablet asignada", - "Incorrect pin": "Pin incorrecto.", + "Incorrect pin": "Pin incorrecto", "You already have the mailAlias": "Ya tienes este alias de correo", "The alias cant be modified": "Este alias de correo no puede ser modificado", "No tickets to invoice": "No hay tickets para facturar" diff --git a/modules/account/front/role/card/index.spec.js b/modules/account/front/role/card/index.spec.js index f02c08f28..569fe487d 100644 --- a/modules/account/front/role/card/index.spec.js +++ b/modules/account/front/role/card/index.spec.js @@ -1,6 +1,6 @@ import './index'; -fdescribe('component vnRoleCard', () => { +describe('component vnRoleCard', () => { let controller; let $httpBackend; diff --git a/modules/account/front/role/descriptor/index.spec.js b/modules/account/front/role/descriptor/index.spec.js index eafb96727..f3b2e4763 100644 --- a/modules/account/front/role/descriptor/index.spec.js +++ b/modules/account/front/role/descriptor/index.spec.js @@ -1,6 +1,6 @@ import './index'; -fdescribe('component vnRoleDescriptor', () => { +describe('component vnRoleDescriptor', () => { let controller; let $httpBackend; diff --git a/modules/worker/back/methods/worker-time-control/addTimeEntry.js b/modules/worker/back/methods/worker-time-control/addTimeEntry.js index 5dbac51ca..86ef12c49 100644 --- a/modules/worker/back/methods/worker-time-control/addTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/addTimeEntry.js @@ -46,6 +46,6 @@ module.exports = Self => { if (!isSubordinate || (isHimself && !isTeamBoss)) throw new UserError(`You don't have enough privileges`); - return Self.clockIn(workerId, args.timed, args.direction, myOptions); + return Self.clockIn(workerId, args.timed, args.direction, null, myOptions); }; }; diff --git a/modules/worker/back/methods/worker-time-control/clockIn.js b/modules/worker/back/methods/worker-time-control/clockIn.js index 44e0c547a..2bc3f16ac 100644 --- a/modules/worker/back/methods/worker-time-control/clockIn.js +++ b/modules/worker/back/methods/worker-time-control/clockIn.js @@ -18,7 +18,10 @@ module.exports = Self => { arg: 'direction', type: 'string' }, - + { + arg: 'device', + type: 'string' + }, ], http: { path: `/clockIn`, @@ -30,13 +33,19 @@ module.exports = Self => { } }); - Self.clockIn = async(workerFk, timed, direction, options) => { + Self.clockIn = async(workerFk, timed, direction, device, options) => { const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - const query = 'CALL vn.workerTimeControl_clockIn(?, ?, ?)'; - const [[response]] = await Self.rawSql(query, [workerFk, timed, direction], myOptions); + const query = 'CALL vn.workerTimeControl_clockIn(?, ?, ?, ?)'; + const [[response]] = await Self.rawSql(query, [ + workerFk, + timed, + direction, + (device || null)], + myOptions); + if (response && response.error) throw new UserError(response.error); diff --git a/modules/worker/back/methods/worker-time-control/login.js b/modules/worker/back/methods/worker-time-control/login.js index 9aa4bd145..6024a689a 100644 --- a/modules/worker/back/methods/worker-time-control/login.js +++ b/modules/worker/back/methods/worker-time-control/login.js @@ -1,7 +1,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - Self.remoteMethodCtx('login', { + Self.remoteMethod('login', { description: 'Consult the user\'s information and the buttons that must be activated after logging in', accessType: 'READ', accepts: [ @@ -21,15 +21,14 @@ module.exports = Self => { } }); - Self.login = async(ctx, pin, options) => { + Self.login = async(pin, options) => { const myOptions = {}; - const $t = ctx.req.__; if (typeof options == 'object') Object.assign(myOptions, options); const query = `CALL vn.workerTimeControl_login(?)`; const [[user]] = await Self.rawSql(query, [pin], myOptions); - if (!user) throw new UserError($t('Incorrect pin')); + if (!user) throw new UserError('Incorrect pin'); return user; }; }; diff --git a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js index 9cd3ed1c0..ff4cac7b7 100644 --- a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js @@ -30,7 +30,7 @@ describe('workerTimeControl clockIn()', () => { try { const options = {transaction: tx}; - await models.WorkerTimeControl.clockIn(workerId, inTime, 'in', options); + await models.WorkerTimeControl.clockIn(workerId, inTime, 'in', 'test', options); const isClockIn = await models.WorkerTimeControl.findOne({ where: { userFk: workerId diff --git a/modules/worker/back/methods/worker-time-control/specs/login.spec.js b/modules/worker/back/methods/worker-time-control/specs/login.spec.js index d9f2dbb39..e125a876d 100644 --- a/modules/worker/back/methods/worker-time-control/specs/login.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/login.spec.js @@ -3,29 +3,15 @@ const LoopBackContext = require('loopback-context'); const UserError = require('vn-loopback/util/user-error'); describe('workerTimeControl login()', () => { - let ctx; - beforeAll(async() => { - ctx = { - accessToken: {userId: 9}, - req: { - headers: {origin: 'http://localhost'}, - __: key => key - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx - }); - }); - it('should correctly login', async() => { - const response = await models.WorkerTimeControl.login(ctx, 9); + const response = await models.WorkerTimeControl.login(9); expect(response.name).toBe('developer'); }); it('should throw UserError if pin is not provided', async() => { try { - await models.WorkerTimeControl.login(ctx); + await models.WorkerTimeControl.login(); } catch (error) { expect(error).toBeInstanceOf(UserError); expect(error.message).toBe('Incorrect pin'); diff --git a/modules/worker/back/models/worker-time-control.json b/modules/worker/back/models/worker-time-control.json index c40989d84..e2b74875a 100644 --- a/modules/worker/back/models/worker-time-control.json +++ b/modules/worker/back/models/worker-time-control.json @@ -14,13 +14,16 @@ "timed": { "type": "date" }, + "direction": { + "type": "string" + }, "manual": { "type": "boolean" }, "order": { "type": "number" }, - "direction": { + "device": { "type": "string" }, "isSendMail": {