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 => {
|
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},
|
2018-08-23 10:31:04 +00:00
|
|
|
fields: 'amount'
|
|
|
|
});
|
2020-06-30 08:16:22 +00:00
|
|
|
|
2020-06-29 12:26:27 +00:00
|
|
|
return workerMana ? workerMana.amount : 0;
|
2018-05-11 09:16:16 +00:00
|
|
|
};
|
|
|
|
};
|