#6274 workerTimeControl #1858
|
@ -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`();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
jorgep marked this conversation as resolved
Outdated
|
||||
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
alexm
commented
Si es el caso puedes hacer:
Es decir, hacer 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;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
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.
Refactor aplicado tras revisión en persona.