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
|
|
|
},
|
2023-11-28 13:48:03 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-12-05 10:53:27 +00:00
|
|
|
Self.clockIn = async(workerFk, timed, direction, options) => {
|
2023-11-23 12:25:31 +00:00
|
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2023-12-05 10:53:27 +00:00
|
|
|
const query = 'CALL vn.workerTimeControl_clockIn(?, ?, ?)';
|
2023-12-21 12:58:33 +00:00
|
|
|
const [[response]] = await Self.rawSql(query, [workerFk, timed, direction], myOptions);
|
|
|
|
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
|
|
|
};
|
|
|
|
};
|