diff --git a/services/loopback/common/methods/workerMana/getCurrentWorkerMana.js b/services/loopback/common/methods/workerMana/getCurrentWorkerMana.js index a8a6ae892..7be2312e6 100644 --- a/services/loopback/common/methods/workerMana/getCurrentWorkerMana.js +++ b/services/loopback/common/methods/workerMana/getCurrentWorkerMana.js @@ -14,7 +14,16 @@ module.exports = Self => { }); Self.getCurrentWorkerMana = async ctx => { - let loggedWorkerId = ctx.req.accessToken.userId; - return await Self.rawSql(`SELECT used AS mana FROM vn.manaSpellers WHERE worker = ?`, [loggedWorkerId]); + let currentClientId = ctx.req.accessToken.userId; + let currentWorker = await Self.app.models.Worker.findOne({ + where: {userFk: currentClientId}, + fields: 'id' + }); + let currentWorkerMana = await Self.app.models.WorkerMana.findOne({ + where: {workerFk: currentWorker.id}, + fields: 'amount' + }); + + return currentWorkerMana ? currentWorkerMana.amount : 0; }; };