55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
const UserError = require('vn-loopback/util/user-error');
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethod('clockIn', {
|
|
description: 'Check if the employee can clock in',
|
|
accessType: 'WRITE',
|
|
accepts: [
|
|
{
|
|
arg: 'workerFk',
|
|
type: 'number',
|
|
required: true,
|
|
},
|
|
{
|
|
arg: 'timed',
|
|
type: 'date'
|
|
},
|
|
{
|
|
arg: 'direction',
|
|
type: 'string'
|
|
},
|
|
{
|
|
arg: 'device',
|
|
type: 'string'
|
|
},
|
|
],
|
|
http: {
|
|
path: `/clockIn`,
|
|
verb: 'POST'
|
|
},
|
|
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);
|
|
|
|
if (response && response.error)
|
|
throw new UserError(response.error);
|
|
|
|
return response;
|
|
};
|
|
};
|