30 lines
868 B
JavaScript
30 lines
868 B
JavaScript
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 => {
|
|
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;
|
|
};
|
|
};
|