salix/modules/worker/back/methods/worker/mySubordinates.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-05-17 11:27:51 +00:00
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('mySubordinates', {
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: {
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;
const userId = ctx.req.accessToken.userId;
2019-05-17 11:27:51 +00:00
const stmts = [];
const myOptions = {};
2021-06-10 09:24:32 +00:00
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;
2019-10-10 10:14:21 +00:00
stmts.push('DROP TEMPORARY TABLE tmp.subordinate');
2019-05-17 11:27:51 +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
return result[queryIndex];
2019-05-17 11:27:51 +00:00
};
};