Service gets if a client has got a Role customer -
getRoleCustomer
This commit is contained in:
parent
0a900fbb80
commit
7f6e9fc617
|
@ -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)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue