salix/modules/client/back/methods/client/getDebt.js

34 lines
852 B
JavaScript

module.exports = Self => {
Self.remoteMethod('getDebt', {
description: 'Returns the boolean debt of a client',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'client id',
http: {source: 'path'}
}],
returns: {
type: 'number',
root: true
},
http: {
path: `/:id/getDebt`,
verb: 'GET'
}
});
Self.getDebt = async(clientFk, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
const [debt] = await Self.rawSql(query, [clientFk], myOptions);
return debt;
};
};