2023-12-05 10:53:27 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
|
|
|
|
2023-11-23 12:25:31 +00:00
|
|
|
module.exports = Self => {
|
2023-11-28 13:48:03 +00:00
|
|
|
Self.remoteMethod('clockIn', {
|
2023-11-23 12:25:31 +00:00
|
|
|
description: 'Check if the employee can clock in',
|
2023-11-28 13:48:03 +00:00
|
|
|
accessType: 'WRITE',
|
2023-11-23 12:25:31 +00:00
|
|
|
accepts: [
|
|
|
|
{
|
|
|
|
arg: 'workerFk',
|
2023-12-07 13:47:22 +00:00
|
|
|
type: 'number',
|
2023-11-23 12:25:31 +00:00
|
|
|
required: true,
|
|
|
|
},
|
2023-12-05 10:53:27 +00:00
|
|
|
{
|
|
|
|
arg: 'timed',
|
|
|
|
type: 'date'
|
|
|
|
},
|
2023-11-23 12:25:31 +00:00
|
|
|
{
|
|
|
|
arg: 'direction',
|
2023-11-28 13:48:03 +00:00
|
|
|
type: 'string'
|
2023-11-23 12:25:31 +00:00
|
|
|
},
|
2024-01-31 08:04:30 +00:00
|
|
|
{
|
|
|
|
arg: 'device',
|
|
|
|
type: 'string'
|
|
|
|
},
|
2023-11-23 12:25:31 +00:00
|
|
|
],
|
|
|
|
http: {
|
|
|
|
path: `/clockIn`,
|
|
|
|
verb: 'POST'
|
2023-11-28 13:48:03 +00:00
|
|
|
},
|
|
|
|
returns: {
|
|
|
|
type: 'Object',
|
|
|
|
root: true
|
2023-11-23 12:25:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-31 08:04:30 +00:00
|
|
|
Self.clockIn = async(workerFk, timed, direction, device, options) => {
|
2023-11-23 12:25:31 +00:00
|
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2024-01-31 08:04:30 +00:00
|
|
|
const query = 'CALL vn.workerTimeControl_clockIn(?, ?, ?, ?)';
|
|
|
|
const [[response]] = await Self.rawSql(query, [
|
|
|
|
workerFk,
|
|
|
|
timed,
|
|
|
|
direction,
|
2024-01-31 12:16:56 +00:00
|
|
|
(device || null)],
|
2024-01-31 08:04:30 +00:00
|
|
|
myOptions);
|
|
|
|
|
2023-12-21 12:58:33 +00:00
|
|
|
if (response && response.error)
|
|
|
|
throw new UserError(response.error);
|
2023-12-05 10:53:27 +00:00
|
|
|
|
|
|
|
return response;
|
2023-11-23 12:25:31 +00:00
|
|
|
};
|
|
|
|
};
|