salix/modules/worker/back/methods/worker-time-control/clockIn.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-12-05 10:53:27 +00:00
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
2023-11-28 13:48:03 +00:00
Self.remoteMethod('clockIn', {
description: 'Check if the employee can clock in',
2023-11-28 13:48:03 +00:00
accessType: 'WRITE',
accepts: [
{
arg: 'workerFk',
2023-12-07 13:47:22 +00:00
type: 'number',
required: true,
},
2023-12-05 10:53:27 +00:00
{
arg: 'timed',
type: 'date'
},
{
arg: 'direction',
2023-11-28 13:48:03 +00:00
type: 'string'
},
2023-11-28 13:48:03 +00:00
],
http: {
path: `/clockIn`,
verb: 'POST'
2023-11-28 13:48:03 +00:00
},
returns: {
type: 'Object',
root: true
}
});
2023-12-05 10:53:27 +00:00
Self.clockIn = async(workerFk, timed, direction, options) => {
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;
};
};