refs #6274 time control methods migrated
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2023-11-23 13:25:31 +01:00
parent 756e55f5c2
commit e314a67fe7
4 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,34 @@
module.exports = Self => {
Self.remoteMethodCtx('clockIn', {
description: 'Check if the employee can clock in',
accessType: 'READ',
accepts: [
{
arg: 'workerFk',
type: 'integer',
required: true,
},
{
arg: 'direction',
type: 'integer'
},
{
arg: 'key',
type: 'string',
}
],
http: {
path: `/clockIn`,
verb: 'POST'
}
});
Self.clockIn = async(ctx, pin, direction, key, 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], options);
};
};

View File

@ -0,0 +1,30 @@
module.exports = Self => {
Self.remoteMethodCtx('getClockIn', {
description: 'Shows the clockings for each day, in columns per day',
accessType: 'READ',
accepts: [
{
arg: 'workerFk',
type: 'int',
required: true,
},
{
arg: 'key',
type: 'string',
}
],
http: {
path: `/getClockIn`,
verb: 'POST'
}
});
Self.getClockIn = async(ctx, workerFk, key, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const query = `CALL vn.workerTimeControl_getClockIn(?, CURDATE())`;
return await Self.rawSql(query, [workerFk], myOptions);
};
};

View File

@ -0,0 +1,39 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('login', {
description: 'Consult the user\'s information and the buttons that must be activated after logging in',
accessType: 'READ',
accepts: [
{
arg: 'pin',
type: 'string',
required: true,
},
{
arg: 'key',
type: 'string',
}
],
returns: {
type: 'Object',
root: true
},
http: {
path: `/login`,
verb: 'POST'
}
});
Self.login = async(ctx, pin, key, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const query = `CALL vn.workerTimeControl_login(?)`;
const user = await Self.rawSql(query, [pin], myOptions);
if (!user) throw new UserError('Indique el pin.');
return user;
};
};

View File

@ -10,6 +10,9 @@ module.exports = Self => {
require('../methods/worker-time-control/weeklyHourRecordEmail')(Self);
require('../methods/worker-time-control/getMailStates')(Self);
require('../methods/worker-time-control/resendWeeklyHourEmail')(Self);
require('../methods/worker-time-control/login')(Self);
require('../methods/worker-time-control/getClockIn')(Self);
require('../methods/worker-time-control/clockIn')(Self);
Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY')