diff --git a/services/client/common/methods/client/roles.js b/services/client/common/methods/client/roles.js new file mode 100644 index 000000000..6d494f35d --- /dev/null +++ b/services/client/common/methods/client/roles.js @@ -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) + }); + }; +} \ No newline at end of file diff --git a/services/client/common/models/client.js b/services/client/common/models/client.js index ea0ba81bf..4c99400c7 100644 --- a/services/client/common/models/client.js +++ b/services/client/common/models/client.js @@ -12,6 +12,7 @@ module.exports = function(Client) { require('../methods/client/create.js')(Client); require('../methods/client/employee.js')(Client); require('../methods/client/filter.js')(Client); + require('../methods/client/roles.js')(Client); // Validations