refs #6274 refactor clockIn
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Jorge Penadés 2023-12-05 11:53:27 +01:00
parent 419ab41816
commit 25006a938b
3 changed files with 15 additions and 8 deletions

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');
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);
if (response[0] && response[0].error)
throw new UserError(response[0].error);
return response;
};
};