2018-05-11 09:16:16 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('getCurrentWorkerMana', {
|
|
|
|
description: 'Returns the mana of the logged worker',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [],
|
|
|
|
returns: {
|
|
|
|
type: 'number',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/getCurrentWorkerMana`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.getCurrentWorkerMana = async ctx => {
|
2018-08-23 10:31:04 +00:00
|
|
|
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;
|
2018-05-11 09:16:16 +00:00
|
|
|
};
|
|
|
|
};
|