2018-05-11 09:30:05 +00:00
|
|
|
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
|
2019-06-11 06:54:03 +00:00
|
|
|
FROM vn.recovery
|
|
|
|
WHERE clientFk = ?
|
2018-05-11 09:30:05 +00:00
|
|
|
AND IFNULL(finished,CURDATE()) >= CURDATE();`,
|
|
|
|
[id]
|
|
|
|
);
|
|
|
|
return result[0].hasActiveRecovery != 0;
|
|
|
|
};
|
|
|
|
};
|