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

30 lines
841 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;
console.log(userId);
let workerMana = await Self.app.models.WorkerMana.findOne({
where: {workerFk: userId},
fields: 'amount'
});
2020-06-29 12:26:27 +00:00
let workerMana1 = await Self.app.models.WorkerMana.find();
console.log(workerMana);
console.log(workerMana1);
return workerMana ? workerMana.amount : 0;
};
};