salix/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js

27 lines
679 B
JavaScript
Raw Normal View History

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 => {
2020-06-29 12:26:27 +00:00
let userId = ctx.req.accessToken.userId;
let workerMana = await Self.app.models.WorkerMana.findOne({
where: {workerFk: userId},
fields: 'amount'
});
2020-06-30 08:16:22 +00:00
2020-06-29 12:26:27 +00:00
return workerMana ? workerMana.amount : 0;
};
};