From a0bc7f68defe04195d5f3be595342120d4066b4d Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 24 Jan 2017 10:15:13 +0100 Subject: [PATCH 1/3] account con relation --- services/client/common/models/account.json | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/client/common/models/account.json b/services/client/common/models/account.json index f84e260ed..f94328103 100644 --- a/services/client/common/models/account.json +++ b/services/client/common/models/account.json @@ -3,17 +3,19 @@ "base": "PersistedModel", "validateUpsert": true, "properties": { - "id": { - "type": "Number", - "id": true, - "description": "Identifier" - }, "name": { "type": "string", "required": true }, "active": { "type": "boolean" + }, + "relations":{ + "id":{ + "type": "hasOne", + "model": "Client", + "foreignKey": "id" + } } } } From ab7342e6a010a71004ceab43bc8952c1781af6c1 Mon Sep 17 00:00:00 2001 From: nelo Date: Tue, 24 Jan 2017 12:30:17 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Modificaci=C3=B3n=20en=20client=20para=20qu?= =?UTF-8?q?e=20meta=20el=20nombre=20en=20el=20put.=20Cambio=20de=20relacio?= =?UTF-8?q?nes=20en=20client=20para=20sacar=20account=20fuera.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../crud/src/client/descriptor/descriptor.js | 4 +- services/client/common/models/Client.js | 4 +- services/client/common/models/Client.json | 58 +++++++++++-------- .../client/common/models/ClientObservation.js | 1 - services/client/common/models/account.json | 19 +++--- 5 files changed, 50 insertions(+), 36 deletions(-) diff --git a/@salix/crud/src/client/descriptor/descriptor.js b/@salix/crud/src/client/descriptor/descriptor.js index a8ccfc23b..beaaf941d 100644 --- a/@salix/crud/src/client/descriptor/descriptor.js +++ b/@salix/crud/src/client/descriptor/descriptor.js @@ -19,8 +19,8 @@ export const COMPONENT = { $scope.$watch('descriptor.client.active', function(newValue, oldValue) { if (self.client && self.clientOld && self.client.active !== self.clientOld.active) { - self.client.modify = "Active"; - $http.put('/client/api/Clients', self.client).then( + var newClient = {id: self.client.id, active: self.client.active, modify: "Active"}; + $http.put('/client/api/Clients', newClient).then( json => { self.client = json.data; self.copyClient(); diff --git a/services/client/common/models/Client.js b/services/client/common/models/Client.js index 707d45607..0fae09502 100644 --- a/services/client/common/models/Client.js +++ b/services/client/common/models/Client.js @@ -14,7 +14,7 @@ module.exports = function(Client) { } // Hooks - Client.observe('before save', function (ctx, next) { + Client.observe('before save', function (ctx, next) { if (ctx.instance) { if (!ctx.instance.dueDay){ ctx.instance.dueDay = 5; @@ -27,6 +27,8 @@ module.exports = function(Client) { if (item.payMethod != ctx.data.payMethod && item.dueDay == ctx.data.dueDay) { ctx.data.dueDay = 5; } + if(!ctx.data.name) + ctx.data.name = item.name; } next(); } diff --git a/services/client/common/models/Client.json b/services/client/common/models/Client.json index 6114b676f..004e0daf3 100644 --- a/services/client/common/models/Client.json +++ b/services/client/common/models/Client.json @@ -11,7 +11,7 @@ "name": { "type": "string", "required": true - }, + }, "fi": { "type": "string", "description": "Fiscal indetifier" @@ -64,8 +64,8 @@ "dueDay": { "type": "Number" }, - "gestdoc":{ - "type":"Number" + "gestdoc": { + "type": "Number" }, "surcharge": { "type": "boolean", @@ -80,26 +80,38 @@ "description": "Send invoices by email" }, "relations": { - "salesPerson": { - "type": "belongsTo", - "model": "SalesPerson", - "foreignKey": "salePersonId" - }, - "paymentMethod":{ - "type": "belongsTo", - "model": "PaymentMethod", - "foreingKey": "payId" - }, - "country":{ - "type": "belongsTo", - "model": "Country", - "foreignKey": "countryId" - }, - "province":{ - "type": "belongsTo", - "model": "Province", - "foreignKey": "provinceId" + "type": { + "salesPerson": { + "type": "belongsTo", + "model": "SalesPerson", + "foreignKey": "salePersonId" + }, + "paymentMethod": { + "type": "belongsTo", + "model": "PaymentMethod", + "foreingKey": "payId" + }, + "country": { + "type": "belongsTo", + "model": "Country", + "foreignKey": "countryId" + }, + "province": { + "type": "belongsTo", + "model": "Province", + "foreignKey": "provinceId" + } } } - } + }, + "validations": [], + "relations": { + "account": { + "type": "hasOne", + "model": "Account", + "foreignKey": "id" + } + }, + "acls": [], + "methods": {} } diff --git a/services/client/common/models/ClientObservation.js b/services/client/common/models/ClientObservation.js index d91d1b70d..3338e33e9 100644 --- a/services/client/common/models/ClientObservation.js +++ b/services/client/common/models/ClientObservation.js @@ -6,7 +6,6 @@ module.exports = function(ClientObservation) { } ClientObservation.observe('before save', function (ctx, next) { - var loopback = require('loopback'); ctx.instance.creationDate = Date(); next(); }); diff --git a/services/client/common/models/account.json b/services/client/common/models/account.json index f94328103..c228640a4 100644 --- a/services/client/common/models/account.json +++ b/services/client/common/models/account.json @@ -3,19 +3,20 @@ "base": "PersistedModel", "validateUpsert": true, "properties": { + "id": { + "type": "number", + "required": true + }, "name": { "type": "string", "required": true - }, + }, "active": { "type": "boolean" - }, - "relations":{ - "id":{ - "type": "hasOne", - "model": "Client", - "foreignKey": "id" - } } - } + }, + "validations": [], + "relations": {}, + "acls": [], + "methods": {} } From 910d0da9b555baee60955e41c246dd408ac09471 Mon Sep 17 00:00:00 2001 From: nelo Date: Tue, 24 Jan 2017 14:24:51 +0100 Subject: [PATCH 3/3] Put con id del cliente Recuperamos account en el get del client. --- @salix/crud/src/client/basic-data/index.js | 3 +-- @salix/crud/src/client/card/card.js | 2 +- @salix/crud/src/client/fiscal-data/index.js | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/@salix/crud/src/client/basic-data/index.js b/@salix/crud/src/client/basic-data/index.js index 3bdc10828..e33bf2f9b 100644 --- a/@salix/crud/src/client/basic-data/index.js +++ b/@salix/crud/src/client/basic-data/index.js @@ -35,8 +35,7 @@ export const COMPONENT = { if (!equalsObject(this.client, this.clientOld)) { var newClient = modified(this.client, this.clientOld); newClient.modify = "BasicData"; - newClient.id = this.clientOld.id; - $http.put('/client/api/Clients', newClient).then( + $http.put(`/client/api/Clients/${this.clientOld.id}`, newClient).then( json => { copyObject(json.data, this.client); this.copyClient(); diff --git a/@salix/crud/src/client/card/card.js b/@salix/crud/src/client/card/card.js index 9057da916..396473fd6 100644 --- a/@salix/crud/src/client/card/card.js +++ b/@salix/crud/src/client/card/card.js @@ -10,7 +10,7 @@ export const COMPONENT = { controllerAs: 'card', controller: function($http, $stateParams) { this.client = null; - $http.get(`/client/api/Clients/${$stateParams.id}`).then( + $http.get(`/client/api/Clients/${$stateParams.id}?filter[include][account]`).then( json => this.client = json.data ); diff --git a/@salix/crud/src/client/fiscal-data/index.js b/@salix/crud/src/client/fiscal-data/index.js index 1ea6c3515..759eaa361 100644 --- a/@salix/crud/src/client/fiscal-data/index.js +++ b/@salix/crud/src/client/fiscal-data/index.js @@ -16,8 +16,7 @@ export const COMPONENT = { if (!equalsObject(this.client, this.clientOld)) { var newClient = modified(this.client, this.clientOld); newClient.modify = "FiscalData"; - newClient.id = this.clientOld.id; - $http.put('/client/api/Clients', this.client).then( + $http.put(`/client/api/Clients/${this.clientOld.id}`, newClient).then( json => { this.client = json.data; this.copyClient();