Tarea #551 /workerMana/getCurrentWorkerMana.js

This commit is contained in:
gerard 2018-08-23 12:31:04 +02:00
parent 7f6f99dc49
commit b558d79757
1 changed files with 11 additions and 2 deletions

View File

@ -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;
};
};