36 lines
963 B
JavaScript
36 lines
963 B
JavaScript
module.exports = Self => {
|
|
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'
|
|
}
|
|
});
|
|
|
|
Self.getDebt = async(ctx, clientFk, options) => {
|
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const date = Date.vnNew();
|
|
date.setHours(0, 0, 0, 0);
|
|
const query = `SELECT vn.client_getDebt(?, ?) AS debt`;
|
|
const [debt] = await Self.rawSql(query, [clientFk, date], myOptions);
|
|
|
|
return debt;
|
|
};
|
|
};
|