#7002 update direction if device exists #2206
|
@ -71,6 +71,34 @@ describe('workerTimeControl clockIn()', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should updates the time entry direction and remaining not be manual', 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-25T16:00:00.000Z";
|
||||
ctx.args = {timed: middleTime, direction: 'middle'};
|
||||
const middleEntryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
middleEntryTime.updateAttribute('manual', false);
|
||||
|
||||
const direction = 'out';
|
||||
const outTimeEntryId = await models.WorkerTimeControl.updateTimeEntry(ctx, middleEntryTime.id, direction, options);
|
||||
|
||||
const outTimeEntry = await models.WorkerTimeControl.findById(outTimeEntryId, null, options);
|
||||
expect(outTimeEntry.manual).toBeFalsy();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
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;
|
||||
|
@ -144,7 +172,7 @@ describe('workerTimeControl clockIn()', () => {
|
|||
const middleTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
const direction = 'out';
|
||||
const {id:outTimeEntryId} = await models.WorkerTimeControl.updateTimeEntry(
|
||||
const outTimeEntryId = await models.WorkerTimeControl.updateTimeEntry(
|
||||
ctx, middleTime.id, direction, options
|
||||
);
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ module.exports = Self => {
|
|||
Self.updateTimeEntry = async(ctx, timeEntryId, direction, options) => {
|
||||
const currentUserId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
const myOptions = {userId: currentUserId};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
|
@ -41,7 +41,7 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
const {id, userFk, timed} = await Self.findById(timeEntryId, null, myOptions);
|
||||
const {id, userFk, timed, manual} = 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 == userFk;
|
||||
|
@ -50,12 +50,15 @@ module.exports = Self => {
|
|||
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 {id: newTimeEntryId} = await Self.clockIn(
|
||||
userFk, timed, direction, null, myOptions
|
||||
);
|
||||
|
||||
if (!manual) await Self.updateAll({id: newTimeEntryId}, {manual: false}, myOptions);
|
||||
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, userFk, timed, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return timeEntryUpdatedId;
|
||||
return newTimeEntryId;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
Loading…
Reference in New Issue