#7211 check if there's available clockIn #2368

Merged
jorgep merged 5 commits from 7211-fixWorkerTimeControl into dev 2024-04-25 15:23:17 +00:00
3 changed files with 41 additions and 5 deletions

View File

@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [24.20.01] - 2024-05-14 ## [24.20.01] - 2024-05-14
### Fixed
- (Worker -> time-control) Corrección de errores
## [24.18.01] - 2024-05-07 ## [24.18.01] - 2024-05-07
## [24.16.01] - 2024-04-18 ## [24.16.01] - 2024-04-18

View File

@ -121,15 +121,17 @@ BEGIN
CALL util.throw(vErrorCode); CALL util.throw(vErrorCode);
END IF; END IF;
-- DIRECCION CORRECTA -- DIRECCION CORRECTA
CALL workerTimeControl_direction(vWorkerFk, vTimed); CALL workerTimeControl_direction(vWorkerFk, vTimed);
IF (SELECT IF (SELECT
IF(IF(option1 IN ('inMiddle', 'outMiddle'), IF((IF(option1 IN ('inMiddle', 'outMiddle'),
'middle', 'middle',
option1) <> vDirection option1) <> vDirection
AND IF(option2 IN ('inMiddle', 'outMiddle'), AND IF(option2 IN ('inMiddle', 'outMiddle'),
'middle', 'middle',
IFNULL(option2, '')) <> vDirection, IFNULL(option2, '')) <> vDirection)
OR (option1 IS NULL AND option2 IS NULL),
TRUE , TRUE ,
FALSE) FALSE)
FROM tmp.workerTimeControlDirection FROM tmp.workerTimeControlDirection
@ -137,12 +139,17 @@ BEGIN
SET vIsError = TRUE; SET vIsError = TRUE;
END IF; END IF;
DROP TEMPORARY TABLE tmp.workerTimeControlDirection;
IF vIsError THEN IF vIsError THEN
SET vErrorCode = 'WRONG_DIRECTION'; SET vErrorCode = 'WRONG_DIRECTION';
IF(SELECT option1 IS NULL AND option2 IS NULL
FROM tmp.workerTimeControlDirection) THEN
SET vErrorCode = 'DAY_MAX_TIME';
END IF;
CALL util.throw(vErrorCode); CALL util.throw(vErrorCode);
END IF; END IF;
DROP TEMPORARY TABLE tmp.workerTimeControlDirection;
-- FICHADAS IMPARES -- FICHADAS IMPARES
SELECT timed INTO vLastIn SELECT timed INTO vLastIn
FROM workerTimeControl FROM workerTimeControl

View File

@ -99,6 +99,32 @@ describe('workerTimeControl clockIn()', () => {
} }
}); });
it('should throw an error trying to add an "in" entry if the last clockIn is not out', async() => {
activeCtx.accessToken.userId = HHRRId;
const workerId = teamBossId;
const tx = await models.WorkerTimeControl.beginTransaction({});
try {
const options = {transaction: tx};
ctx.args = {timed: "2000-12-25T21:00:00.000Z", direction: 'in'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
ctx.args = {timed: "2000-12-25T22:00:00.000Z", direction: 'middle'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
ctx.args = {timed: "2000-12-25T22:30:00.000Z", direction: 'middle'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
ctx.args = {timed: "2000-12-26T01:00:00.000Z", direction: 'in'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
await tx.rollback();
} catch (e) {
expect(e.message).toBe('Dirección incorrecta');
await tx.rollback();
}
});
describe('as Role errors', () => { describe('as Role errors', () => {
it('should add if the current user is team boss and the target user is himself', async() => { it('should add if the current user is team boss and the target user is himself', async() => {
activeCtx.accessToken.userId = teamBossId; activeCtx.accessToken.userId = teamBossId;