Service gets if a client has got a Role customer -

getRoleCustomer
This commit is contained in:
Vicente Falco 2017-09-18 07:39:06 +02:00
parent 0a900fbb80
commit 7f6e9fc617
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,45 @@
module.exports = (Client) => {
Client.remoteMethod('getRoleCustomer', {
description: 'devuelve true/false si es Customer el client',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'string',
required: true,
description: 'Model id',
http: {source: 'path'}
},
{
arg: 'filter',
type: 'object',
required: true,
description: 'Filter defining where',
http: function(ctx) {
return ctx.req.query;
}
}
],
returns: {
arg: 'data',
type: String,
root: true
},
http: {
path: `/:id/getRoleCustomer`,
verb: 'get'
}
});
Client.getRoleCustomer = (id, ctx, cb) => {
let query = `SELECT count(*) isCustomer FROM Account ac JOIN Role ON Role.id = ac.roleFK WHERE Role.\`name\`='customer' AND ac.id IN (?)`;
const params = [id];
Client.rawSql(query, params, cb)
.then((response) => {
cb(null, response);
})
.catch((reject) => {
cb (reject, null)
});
};
}

View File

@ -12,6 +12,7 @@ module.exports = function(Client) {
require('../methods/client/create.js')(Client); require('../methods/client/create.js')(Client);
require('../methods/client/employee.js')(Client); require('../methods/client/employee.js')(Client);
require('../methods/client/filter.js')(Client); require('../methods/client/filter.js')(Client);
require('../methods/client/roles.js')(Client);
// Validations // Validations