43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethod('mySubordinates', {
|
|
description: 'Returns a list of a subordinated 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, options) => {
|
|
const conn = Self.dataSource.connector;
|
|
const userId = ctx.req.accessToken.userId;
|
|
const stmts = [];
|
|
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
stmts.push(new ParameterizedSQL('CALL vn.subordinateGetList(?)', [userId]));
|
|
const queryIndex = stmts.push('SELECT * FROM tmp.subordinate') - 1;
|
|
stmts.push('DROP TEMPORARY TABLE tmp.subordinate');
|
|
|
|
const sql = ParameterizedSQL.join(stmts, ';');
|
|
const result = await conn.executeStmt(sql, myOptions);
|
|
|
|
return result[queryIndex];
|
|
};
|
|
};
|