From dac95805e8d4cbae5cdd0a3648d67871d422d568 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 14 Apr 2021 09:02:08 +0200 Subject: [PATCH] 2882 - Replaced worker userFk property by user id --- .../back/methods/worker/mySubordinates.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/worker/back/methods/worker/mySubordinates.js b/modules/worker/back/methods/worker/mySubordinates.js index cf45d3a9d..956374964 100644 --- a/modules/worker/back/methods/worker/mySubordinates.js +++ b/modules/worker/back/methods/worker/mySubordinates.js @@ -3,7 +3,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; module.exports = Self => { Self.remoteMethod('mySubordinates', { - description: 'Returns a list of a subordinate workers', + description: 'Returns a list of a subordinated workers', accessType: 'READ', accepts: [{ arg: 'ctx', @@ -11,7 +11,7 @@ module.exports = Self => { http: {source: 'context'} }], returns: { - type: ['Object'], + type: ['object'], root: true }, http: { @@ -22,19 +22,16 @@ module.exports = Self => { 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 userId = ctx.req.accessToken.userId; const stmts = []; - stmts.push(new ParameterizedSQL('CALL vn.subordinateGetList(?)', [myWorker.id])); - stmts.push('SELECT * FROM tmp.subordinate'); + stmts.push(new ParameterizedSQL('CALL vn.subordinateGetList(?)', [userId])); + const queryIndex = stmts.push('SELECT * FROM tmp.subordinate') - 1; stmts.push('DROP TEMPORARY TABLE tmp.subordinate'); - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await conn.executeStmt(sql); + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await conn.executeStmt(sql); - return result[1]; + return result[queryIndex]; }; };