42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethod('mySubordinates', {
|
|
description: 'Returns a list of a subordinate workers',
|
|
accessType: 'READ',
|
|
accepts: [{
|
|
arg: 'ctx',
|
|
type: 'Object',
|
|
http: {source: 'context'}
|
|
}],
|
|
returns: {
|
|
type: ['Object'],
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/mySubordinates`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.mySubordinates = async ctx => {
|
|
const conn = Self.dataSource.connector;
|
|
const myUserId = ctx.req.accessToken.userId;
|
|
const myWorker = await Self.app.models.Worker.findOne({
|
|
where: {userFk: myUserId}
|
|
});
|
|
const stmts = [];
|
|
|
|
stmts.push(new ParameterizedSQL('CALL vn.subordinateGetList(?)', [myWorker.id]));
|
|
stmts.push('SELECT * FROM tmp.subordinate');
|
|
stmts.push('DROP TEMPORARY TABLE tmp.subordinate');
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
let result = await conn.executeStmt(sql);
|
|
|
|
|
|
return result[1];
|
|
};
|
|
};
|