#6274 workerTimeControl #1858
|
@ -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`();
|
|
@ -1,7 +1,7 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('clockIn', {
|
Self.remoteMethod('clockIn', {
|
||||||
description: 'Check if the employee can clock in',
|
description: 'Check if the employee can clock in',
|
||||||
accessType: 'READ',
|
accessType: 'WRITE',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'workerFk',
|
arg: 'workerFk',
|
||||||
|
@ -10,25 +10,26 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'direction',
|
arg: 'direction',
|
||||||
type: 'integer'
|
type: 'string'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
arg: 'key',
|
|
||||||
type: 'string',
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
http: {
|
http: {
|
||||||
path: `/clockIn`,
|
path: `/clockIn`,
|
||||||
verb: 'POST'
|
verb: 'POST'
|
||||||
|
},
|
||||||
|
returns: {
|
||||||
|
type: 'Object',
|
||||||
|
root: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.clockIn = async(ctx, pin, direction, key, options) => {
|
Self.clockIn = async(workerFk, direction, options) => {
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const query = 'CALL vn.workerTimeControl_clockIn(?, NULL, ?)';
|
const query = 'CALL vn.workerTimeControl_clockIn(?, NULL, ?)';
|
||||||
return await Self.rawSql(query, [workerFk, direction], options);
|
return await Self.rawSql(query, [workerFk, direction], myOptions);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('getClockIn', {
|
Self.remoteMethod('getClockIn', {
|
||||||
description: 'Shows the clockings for each day, in columns per day',
|
description: 'Shows the clockings for each day, in columns per day',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -8,23 +8,25 @@ module.exports = Self => {
|
||||||
type: 'int',
|
type: 'int',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
arg: 'key',
|
|
||||||
type: 'string',
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
http: {
|
http: {
|
||||||
path: `/getClockIn`,
|
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 = {};
|
const myOptions = {};
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const query = `CALL vn.workerTimeControl_getClockIn(?, CURDATE())`;
|
const query = `CALL vn.workerTimeControl_getClockIn(?, CURDATE())`;
|
||||||
return await Self.rawSql(query, [workerFk], myOptions);
|
const [result] = await Self.rawSql(query, [workerFk], myOptions);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
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',
|
description: 'Consult the user\'s information and the buttons that must be activated after logging in',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -10,10 +10,6 @@ module.exports = Self => {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
arg: 'key',
|
|
||||||
type: 'string',
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'Object',
|
type: 'Object',
|
||||||
|
@ -25,7 +21,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.login = async(ctx, pin, key, options) => {
|
Self.login = async(pin, options) => {
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -34,6 +30,6 @@ module.exports = Self => {
|
||||||
const user = await Self.rawSql(query, [pin], myOptions);
|
const user = await Self.rawSql(query, [pin], myOptions);
|
||||||
|
|
||||||
if (!user) throw new UserError('Indique el pin.');
|
if (!user) throw new UserError('Indique el pin.');
|
||||||
return user;
|
return user[0][0];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue