Modificación en client para que meta el nombre en el put.

Cambio de relaciones en client para sacar account fuera.
This commit is contained in:
nelo 2017-01-24 12:30:17 +01:00
parent a0bc7f68de
commit ab7342e6a0
5 changed files with 50 additions and 36 deletions

View File

@ -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();

View File

@ -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();
}

View File

@ -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": {}
}

View File

@ -6,7 +6,6 @@ module.exports = function(ClientObservation) {
}
ClientObservation.observe('before save', function (ctx, next) {
var loopback = require('loopback');
ctx.instance.creationDate = Date();
next();
});

View File

@ -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": {}
}