50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethod('timeControl', {
|
|
description: 'Returns a range of worked hours for a given worker id',
|
|
accessType: 'READ',
|
|
accepts: [
|
|
{
|
|
arg: 'id',
|
|
type: 'number',
|
|
required: true,
|
|
description: 'The worker id',
|
|
http: {source: 'path'}
|
|
},
|
|
{
|
|
arg: 'dateFrom',
|
|
type: 'datetime',
|
|
required: true,
|
|
description: 'the date from the time control begins in format YYYY-mm-dd-hh:mm:ss'
|
|
},
|
|
{
|
|
arg: 'dateTo',
|
|
type: 'datetime',
|
|
required: true,
|
|
description: 'the date when the time control finishes in format YYYY-mm-dd-hh:mm:ss'
|
|
}],
|
|
returns: {
|
|
type: ['Object'],
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/:id/timeControl`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.timeControl = async(id, from, to) => {
|
|
const conn = Self.dataSource.connector;
|
|
const stmts = [];
|
|
|
|
stmts.push(new ParameterizedSQL('CALL vn.timeControl_calculateByUser(?, ?, ?)', [id, from, to]));
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
let result = await conn.executeStmt(sql);
|
|
|
|
return result[0];
|
|
};
|
|
};
|