Tarea #289 Cuando se modifica el crédito mostrar alerta

This commit is contained in:
gerard 2018-05-11 11:30:05 +02:00
parent 23a7dec92d
commit f841e25b7f
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,34 @@
module.exports = Self => {
Self.remoteMethod('hasActiveRecovery', {
description: 'Returns a boolean that is true when a client has an active recovery',
accessType: 'READ',
accepts: [
{
arg: 'clientFk',
type: 'number',
required: true,
description: 'The id of a client',
http: {source: 'path'}
}
],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:clientFk/hasActiveRecovery`,
verb: 'GET'
}
});
Self.hasActiveRecovery = async id => {
let result = await Self.rawSql(
`SELECT count(*) AS hasActiveRecovery
FROM vn.recovery
WHERE clientFk = ?
AND IFNULL(finished,CURDATE()) >= CURDATE();`,
[id]
);
return result[0].hasActiveRecovery != 0;
};
};

View File

@ -1,3 +1,4 @@
module.exports = function(Self) {
require('../methods/recovery/filter')(Self);
require('../methods/recovery/hasActiveRecovery')(Self);
};