2019-05-17 11:27:51 +00:00
|
|
|
|
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
|
|
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('mySubordinates', {
|
2021-04-14 07:02:08 +00:00
|
|
|
description: 'Returns a list of a subordinated workers',
|
2019-05-17 11:27:51 +00:00
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'ctx',
|
|
|
|
type: 'Object',
|
|
|
|
http: {source: 'context'}
|
|
|
|
}],
|
|
|
|
returns: {
|
2021-04-14 07:02:08 +00:00
|
|
|
type: ['object'],
|
2019-05-17 11:27:51 +00:00
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/mySubordinates`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-10 09:24:32 +00:00
|
|
|
Self.mySubordinates = async(ctx, options) => {
|
2019-05-17 11:27:51 +00:00
|
|
|
const conn = Self.dataSource.connector;
|
2021-04-14 07:02:08 +00:00
|
|
|
const userId = ctx.req.accessToken.userId;
|
2019-05-17 11:27:51 +00:00
|
|
|
const stmts = [];
|
|
|
|
|
2021-11-18 10:17:30 +00:00
|
|
|
const myOptions = {};
|
2021-06-10 09:24:32 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2021-04-14 07:02:08 +00:00
|
|
|
stmts.push(new ParameterizedSQL('CALL vn.subordinateGetList(?)', [userId]));
|
|
|
|
const queryIndex = stmts.push('SELECT * FROM tmp.subordinate') - 1;
|
2019-10-10 10:14:21 +00:00
|
|
|
stmts.push('DROP TEMPORARY TABLE tmp.subordinate');
|
2019-05-17 11:27:51 +00:00
|
|
|
|
2021-04-14 07:02:08 +00:00
|
|
|
const sql = ParameterizedSQL.join(stmts, ';');
|
2021-06-10 09:24:32 +00:00
|
|
|
const result = await conn.executeStmt(sql, myOptions);
|
2019-05-17 11:27:51 +00:00
|
|
|
|
2021-04-14 07:02:08 +00:00
|
|
|
return result[queryIndex];
|
2019-05-17 11:27:51 +00:00
|
|
|
};
|
|
|
|
};
|