#6274 workerTimeControl #1858

Merged
jorgep merged 31 commits from 6274-loginWorkerTimeControl into dev 2024-01-03 11:31:52 +00:00
3 changed files with 15 additions and 8 deletions
Showing only changes of commit 25006a938b - Show all commits

View File

@ -8,6 +8,6 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
VALUES
('WorkerTimeControl', 'login', 'READ', 'ALLOW', 'ROLE', 'timeControl'),
('WorkerTimeControl', 'getClockIn', 'READ', 'ALLOW', 'ROLE', 'timeControl'),
('WorkerTimeControl', 'addTimeEntry', 'WRITE', 'ALLOW', 'ROLE', 'timeControl');
('WorkerTimeControl', 'clockIn', 'WRITE', 'ALLOW', 'ROLE', 'timeControl');
CALL `account`.`role_sync`();

View File

@ -46,10 +46,7 @@ module.exports = Self => {
if (!isSubordinate || (isSubordinate && isHimself && !isTeamBoss))
throw new UserError(`You don't have enough privileges`);
query = `CALL vn.workerTimeControl_clockIn(?,?,?)`;
const [response] = await Self.rawSql(query, [workerId, args.timed, args.direction], myOptions);
if (response[0] && response[0].error)
throw new UserError(response[0].error);
const response = await Self.clockIn(workerId, args.timed, args.direction, myOptions);
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, workerId, args.timed, myOptions);

View File

@ -1,3 +1,5 @@
const UserError = require('vn-loopback/util/user-error');
jorgep marked this conversation as resolved Outdated

veo que existe un archivo muy similar que llama al mismo procedimiento, lo has tenido en cuenta? conviene juntarlo en uno?
modules/worker/back/methods/worker-time-control/addTimeEntry.js

veo que existe un archivo muy similar que llama al mismo procedimiento, lo has tenido en cuenta? conviene juntarlo en uno? modules/worker/back/methods/worker-time-control/addTimeEntry.js

Ya se ha implementado, tenemos que mirarlo juntos conforme hemos hablado por rocket.

Ya se ha implementado, tenemos que mirarlo juntos conforme hemos hablado por rocket.

Refactor aplicado tras revisión en persona.

Refactor aplicado tras revisión en persona.
module.exports = Self => {
Self.remoteMethod('clockIn', {
description: 'Check if the employee can clock in',
@ -8,6 +10,10 @@ module.exports = Self => {
type: 'integer',
required: true,
},
{
arg: 'timed',
type: 'date'
},
{
arg: 'direction',
type: 'string'
@ -24,12 +30,16 @@ module.exports = Self => {
}
});
Self.clockIn = async(workerFk, direction, options) => {
Self.clockIn = async(workerFk, timed, direction, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const query = 'CALL vn.workerTimeControl_clockIn(?, NULL, ?)';
return await Self.rawSql(query, [workerFk, direction], myOptions);
const query = 'CALL vn.workerTimeControl_clockIn(?, ?, ?)';
const [response] = await Self.rawSql(query, [workerFk, timed, direction], myOptions);
jorgep marked this conversation as resolved Outdated
Outdated
Review

Si es el caso puedes hacer:

const myArray = [[{}]]
const [[myNewArray]] = myArray
console.log(myNewArray) // Devuelve {}

Es decir, hacer const [[response]] = y te evitas luego hacer response[0]

Si es el caso puedes hacer: ``` const myArray = [[{}]] const [[myNewArray]] = myArray console.log(myNewArray) // Devuelve {} ``` Es decir, hacer `const [[response]] =` y te evitas luego hacer response[0]
if (response[0] && response[0].error)
throw new UserError(response[0].error);
return response;
};
};