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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-08 13:53:30 +00:00
|
|
|
Self.hasActiveRecovery = async(id, options) => {
|
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2023-01-16 14:18:24 +00:00
|
|
|
const date = Date.vnNew();
|
2022-06-09 11:33:01 +00:00
|
|
|
date.setHours(0, 0, 0, 0);
|
2021-07-08 13:53:30 +00:00
|
|
|
const query = `
|
|
|
|
SELECT count(*) AS hasActiveRecovery
|
|
|
|
FROM vn.recovery
|
|
|
|
WHERE clientFk = ?
|
2022-06-09 11:33:01 +00:00
|
|
|
AND IFNULL(finished, ?) >= ?;
|
2021-07-08 13:53:30 +00:00
|
|
|
`;
|
2022-06-09 11:33:01 +00:00
|
|
|
const [result] = await Self.rawSql(query, [id, date, date], myOptions);
|
2021-07-08 13:53:30 +00:00
|
|
|
|
|
|
|
return result.hasActiveRecovery != 0;
|
2018-05-11 09:30:05 +00:00
|
|
|
};
|
|
|
|
};
|