diff --git a/client/core/src/autocomplete/index.js b/client/core/src/autocomplete/index.js index 24db75bb2..422db8d42 100644 --- a/client/core/src/autocomplete/index.js +++ b/client/core/src/autocomplete/index.js @@ -344,12 +344,6 @@ export default class Autocomplete extends Component { this.item = item; this.mdlUpdate(); } - $onChanges(changes) { - if (!changes.initialValue) - this.requestItem(); - else - this.showItem(changes.initialValue); - } } Autocomplete.$inject = ['$element', '$scope', '$http', 'vnPopover']; diff --git a/services/client/common/models/Client.js b/services/client/common/models/Client.js index b7ad468d8..a4bd9a651 100644 --- a/services/client/common/models/Client.js +++ b/services/client/common/models/Client.js @@ -1,6 +1,8 @@ module.exports = function(Client) { - require("../scopes/card.js")(Client); + require("../scopes/client/card.js")(Client); + require("../scopes/client/activate.js")(Client); + require("../scopes/client/addresses.js")(Client); // Validations Client.validatesUniquenessOf('name', {message: 'El nombre debe ser Ășnico'}); @@ -43,36 +45,6 @@ module.exports = function(Client) { } }); - // Methods - - Client.remoteMethod('activate', { - description: 'Activate or deactive client', - accepts: { - arg: 'id', - type: 'number', - required: true, - description: 'Model id', - http: {source: 'path'} - }, - returns: { - arg: 'active', - type: 'boolean' - }, - http: { - verb: 'put', - path: '/:id/activate' - } - }); - - Client.activate = function(id, cb) { - console.log(id); - Client.findById(id, function(err, client) { - if(!err) { - Client.update({id: client.id}, {active: !client.active}); - cb(null, !client.active); - } - }); - }; // Basic filter @@ -94,53 +66,4 @@ module.exports = function(Client) { }; } - // Client addresses - - Client.remoteMethod('addressesList', { - description: 'List items using a filter', - 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: ['Address'], - root: true - }, - http: { - path: `/:id/addressesList`, - verb: 'get' - } - }); - - Client.addressesList = function(id, p, cb) { - let filter = { - where: { - clientFk: id, - }, - skip: (p.page - 1) * p.size, - limit: p.size - }; - - Client.app.models.Address.find(filter, function(err, instances) { - if(!err) { - cb(null, instances); - } - }) - }; }; \ No newline at end of file diff --git a/services/client/common/scopes/client/activate.js b/services/client/common/scopes/client/activate.js new file mode 100644 index 000000000..c3d0ff451 --- /dev/null +++ b/services/client/common/scopes/client/activate.js @@ -0,0 +1,29 @@ +module.exports = function(Client){ + Client.remoteMethod('activate', { + description: 'Activate or deactive client', + accepts: { + arg: 'id', + type: 'number', + required: true, + description: 'Model id', + http: {source: 'path'} + }, + returns: { + arg: 'active', + type: 'boolean' + }, + http: { + verb: 'put', + path: '/:id/activate' + } + }); + + Client.activate = function(id, cb) { + Client.findById(id, function(err, client) { + if(!err) { + Client.update({id: client.id}, {active: !client.active}); + cb(null, !client.active); + } + }); + }; +}; \ No newline at end of file diff --git a/services/client/common/scopes/client/addresses.js b/services/client/common/scopes/client/addresses.js new file mode 100644 index 000000000..d050d5238 --- /dev/null +++ b/services/client/common/scopes/client/addresses.js @@ -0,0 +1,49 @@ +module.exports = function(Client){ + Client.remoteMethod('addressesList', { + description: 'List items using a filter', + 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: ['Address'], + root: true + }, + http: { + path: `/:id/addressesList`, + verb: 'get' + } + }); + + Client.addressesList = function(id, p, cb) { + let filter = { + where: { + clientFk: id, + }, + skip: (p.page - 1) * p.size, + limit: p.size + }; + + Client.app.models.Address.find(filter, function(err, instances) { + if(!err) { + cb(null, instances); + } + }) + }; +} \ No newline at end of file diff --git a/services/client/common/scopes/card.js b/services/client/common/scopes/client/card.js similarity index 100% rename from services/client/common/scopes/card.js rename to services/client/common/scopes/client/card.js diff --git a/services/client/common/scopes/card.json b/services/client/common/scopes/client/card.json similarity index 100% rename from services/client/common/scopes/card.json rename to services/client/common/scopes/client/card.json