refs #6274 back methods created
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Jorge Penadés 2023-11-28 14:48:03 +01:00
parent e314a67fe7
commit 29fb36010c
4 changed files with 37 additions and 25 deletions

View File

@ -0,0 +1,13 @@
INSERT INTO `account`.`role` (name, description)
VALUES ('timeControl','Tablet para fichar');
INSERT INTO `account`.`roleInherit` (role, inheritsFrom)
VALUES (127, 11);
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
VALUES
('workerTimeControl', 'login', 'READ', 'ALLOW', 'ROLE', '*'),
('workerTimeControl', 'getClockIn', 'READ', 'ALLOW', 'ROLE', '*'),
('workerTimeControl', 'clockIn', 'WRITE', 'ALLOW', 'ROLE', '*');
CALL `account`.`role_sync`();

View File

@ -1,7 +1,7 @@
module.exports = Self => {
Self.remoteMethodCtx('clockIn', {
Self.remoteMethod('clockIn', {
description: 'Check if the employee can clock in',
accessType: 'READ',
accessType: 'WRITE',
accepts: [
{
arg: 'workerFk',
@ -10,25 +10,26 @@ module.exports = Self => {
},
{
arg: 'direction',
type: 'integer'
type: 'string'
},
{
arg: 'key',
type: 'string',
}
],
http: {
path: `/clockIn`,
verb: 'POST'
},
returns: {
type: 'Object',
root: true
}
});
Self.clockIn = async(ctx, pin, direction, key, options) => {
Self.clockIn = async(workerFk, 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], options);
return await Self.rawSql(query, [workerFk, direction], myOptions);
};
};

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethodCtx('getClockIn', {
Self.remoteMethod('getClockIn', {
description: 'Shows the clockings for each day, in columns per day',
accessType: 'READ',
accepts: [
@ -8,23 +8,25 @@ module.exports = Self => {
type: 'int',
required: true,
},
{
arg: 'key',
type: 'string',
}
],
http: {
path: `/getClockIn`,
verb: 'POST'
}
verb: 'GET'
},
returns: {
type: ['Object'],
root: true
},
});
Self.getClockIn = async(ctx, workerFk, key, options) => {
Self.getClockIn = async(workerFk, 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);
const [result] = await Self.rawSql(query, [workerFk], myOptions);
return result;
};
};

View File

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