2018-01-29 11:37:54 +00:00
|
|
|
module.exports = function(Self) {
|
2018-09-14 11:43:51 +00:00
|
|
|
Self.remoteMethod('getCard', {
|
|
|
|
description: 'Get client basic data and debt',
|
2018-01-29 11:37:54 +00:00
|
|
|
accepts: {
|
|
|
|
arg: 'id',
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
description: 'The client id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
},
|
|
|
|
returns: {
|
|
|
|
type: 'Object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
verb: 'GET',
|
2018-09-14 11:43:51 +00:00
|
|
|
path: '/:id/getCard'
|
2018-01-29 11:37:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-09-14 11:43:51 +00:00
|
|
|
Self.getCard = async function(id) {
|
|
|
|
let client = await Self.findOne({
|
2018-01-29 11:37:54 +00:00
|
|
|
where: {
|
|
|
|
id: id
|
|
|
|
},
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'salesPerson',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'firstName', 'name']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'contactChannel',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'province',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'country',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'country']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'payMethod',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'account',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name', 'active']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
2018-09-14 11:43:51 +00:00
|
|
|
|
|
|
|
let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
|
|
|
|
client.debt = (await Self.rawSql(query, [id]))[0].debt;
|
|
|
|
|
|
|
|
return client;
|
2018-01-29 11:37:54 +00:00
|
|
|
};
|
|
|
|
};
|