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' }, ], http: { path: `/clockIn`, verb: 'POST' }, returns: { type: 'Object', root: true } }); Self.clockIn = async(workerFk, timed, direction, 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], myOptions); if (response && response.error) throw new UserError(response.error); return response; }; };