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

55 lines
1.3 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'
},
{
arg: 'device',
type: 'string'
},
],
http: {
path: `/clockIn`,
verb: 'POST'
2023-11-28 13:48:03 +00:00
},
returns: {
type: 'Object',
root: true
}
});
Self.clockIn = async(workerFk, timed, direction, device, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const query = 'CALL vn.workerTimeControl_clockIn(?, ?, ?, ?)';
const [[response]] = await Self.rawSql(query, [
workerFk,
timed,
direction,
device || null],
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;
};
};