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

36 lines
963 B
JavaScript
Raw Normal View History

module.exports = Self => {
2023-06-01 06:32:06 +00:00
Self.remoteMethodCtx('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'
}
});
2023-06-01 06:32:06 +00:00
Self.getDebt = async(ctx, clientFk, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
2021-07-08 13:53:30 +00:00
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);
2023-04-12 19:10:50 +00:00
const query = `SELECT vn.client_getDebt(?, ?) AS debt`;
2022-06-09 11:33:01 +00:00
const [debt] = await Self.rawSql(query, [clientFk, date], myOptions);
2018-03-27 13:06:22 +00:00
return debt;
};
};