#6878 hotfix fix add manual entries #2074

Merged
jorgep merged 2 commits from 6878-hotfix-addManualTimeEntries into master 2024-02-23 07:37:12 +00:00
6 changed files with 75 additions and 29 deletions
Showing only changes of commit 76b1433099 - Show all commits

View File

@ -75,7 +75,7 @@ BEGIN
SET vDated = DATE(vTimed);
SELECT IF(pc.name = 'Conductor +3500kg',
SELECT IF(pc.code = 'driveCE',
Review

driverCE

driverCE
wc.dayBreakDriver,
wc.dayBreak),
wc.shortWeekBreak,

View File

@ -0,0 +1,6 @@
ALTER TABLE vn.professionalCategory DROP COLUMN IF EXISTS code;
ALTER TABLE IF EXISTS vn.professionalCategory ADD COLUMN code VARCHAR(25) DEFAULT NULL;
Review

los campos code son UNIQUE

los campos code son UNIQUE
UPDATE vn.professionalCategory
SET code = 'driverCE'
WHERE name = 'Conductor C + E';

View File

@ -46,6 +46,31 @@ describe('workerTimeControl clockIn()', () => {
}
});
it('should throw an error trying to change a middle hour to out not resting 12h', async() => {
activeCtx.accessToken.userId = HHRRId;
const workerId = teamBossId;
const tx = await models.WorkerTimeControl.beginTransaction({});
try {
const options = {transaction: tx};
const entryTime = "2000-12-25T11:00:00.000Z";
ctx.args = {timed: entryTime, direction: 'in'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
const middleTime ="2000-12-26T11:00:00.000Z";
ctx.args = {timed: middleTime, direction: 'middle'};
const middleEntryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
const direction = 'out';
await models.WorkerTimeControl.updateTimeEntry(ctx, middleEntryTime.id, direction, options);
await tx.rollback();
} catch (e) {
expect(e.message).toBe('Superado el tiempo máximo entre entrada y salida');
await tx.rollback();
}
});
describe('as Role errors', () => {
it('should add if the current user is team boss and the target user is himself', async() => {
activeCtx.accessToken.userId = teamBossId;
@ -110,16 +135,22 @@ describe('workerTimeControl clockIn()', () => {
todayAtOne.setHours(1, 0, 0, 0);
ctx.args = {timed: todayAtOne, direction: 'in'};
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
const entryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
expect(entryTime.id).toBeDefined();
const todayAtTwo = Date.vnNew();
expect(createdTimeEntry.id).toBeDefined();
todayAtTwo.setHours(2, 0, 0, 0);
ctx.args = {timed: todayAtTwo, direction: 'middle'};
const middleTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
ctx.args = {direction: 'out'};
const updatedTimeEntry = await models.WorkerTimeControl.updateTimeEntry(
ctx, createdTimeEntry.id, options
const direction = 'out';
const {id:outTimeEntryId} = await models.WorkerTimeControl.updateTimeEntry(
ctx, middleTime.id, direction, options
);
expect(updatedTimeEntry.direction).toEqual('out');
const {direction: updatedDirection} = await models.WorkerTimeControl.findById(outTimeEntryId,{fields:['direction']},options);
expect(updatedDirection).toEqual('out');
await tx.rollback();
} catch (e) {
await tx.rollback();

View File

@ -26,32 +26,39 @@ module.exports = Self => {
}
});
Self.updateTimeEntry = async(ctx, id, options) => {
Self.updateTimeEntry = async(ctx, timeEntryId, direction, options) => {
const currentUserId = ctx.req.accessToken.userId;
const models = Self.app.models;
const args = ctx.args;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
const targetTimeEntry = await Self.findById(id, null, myOptions);
const isSubordinate = await models.Worker.isSubordinate(ctx, targetTimeEntry.userFk, myOptions);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const {id, userFk, timed} = await Self.findById(timeEntryId, null, myOptions);
const isSubordinate = await models.Worker.isSubordinate(ctx, userFk, myOptions);
const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE');
const isHimself = currentUserId == targetTimeEntry.userFk;
const isHimself = currentUserId == userFk;
const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss);
if (notAllowed) throw new UserError(`You don't have enough privileges`);
if (notAllowed)
throw new UserError(`You don't have enough privileges`);
await models.WorkerTimeControl.deleteById(id, myOptions);
const timeEntryUpdatedId = await Self.clockIn(userFk, timed, direction, null, myOptions);
const timeEntryUpdated = await targetTimeEntry.updateAttributes({
direction: args.direction
}, myOptions);
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, userFk, timed, myOptions);
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, targetTimeEntry.userFk, targetTimeEntry.timed, myOptions);
return timeEntryUpdated;
if (tx) await tx.commit();
return timeEntryUpdatedId;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -415,11 +415,13 @@ class Controller extends Section {
throw new Error(`The entry type can't be empty`);
const query = `WorkerTimeControls/${entry.id}/updateTimeEntry`;
if (entry.direction !== entry.$orgRow.direction) {
this.$http.post(query, {direction: entry.direction})
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
.then(() => this.$.editEntry.hide())
.then(() => this.fetchHours())
.then(() => this.getMailStates(this.date));
}
} catch (e) {
this.vnApp.showError(this.$t(e.message));
}

View File

@ -130,7 +130,7 @@ describe('Component vnWorkerTimeControl', () => {
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
controller.date = today;
controller.fetchHours = jest.fn();
controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'};
controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in', $orgRow: {direction: null}};
controller.$.editEntry = {
hide: () => {}
};