Conflicto rama dev

This commit is contained in:
Vicente Falco 2017-10-01 19:59:35 +02:00
parent 495e3b7c5e
commit 8fa1599102
8 changed files with 0 additions and 553 deletions

View File

@ -1,61 +0,0 @@
module.exports = function(Address) {
Address.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'});
function isEnabled(err) {
if (!this.enabled && this.default) err();
}
Address.beforeRemote('create',function(ctx, modelInstance, next){
var data = ctx.req.body;
create(data, next);
});
function create(data, next){
if(data.default){
removeAllDefault(data.client);
}
next();
}
Address.beforeRemote('prototype.updateAttributes',function(ctx, modelInstance, next){
var data = ctx.req.body;
data.id = ctx.req.params.id;
getAddress(ctx, data, next);
});
function getAddress(ctx, data, next){
var address = Address.findOne( {where: { id: data.id}}, function (err, address){
if(address)
callbackGetAddress(ctx, data, address, next)
});
}
function callbackGetAddress(ctx, data, address, next){
if (data.default){
removeAllDefault(address.client);
next();
}
else if (address.default && !data.default)
next(generateErrorDefaultAddress());
else
next();
}
function getData(ctx){
if (ctx.data)
return ctx.data;
else
return ctx.instance;
}
function removeAllDefault(cl){
Address.update({client: cl}, {default: false});
}
function generateErrorDefaultAddress(){
var error = new Error();
error.message = "No se puede desmarcar el consignatario predeterminado";
error.status = 500;
return error;
}
};

View File

@ -1,80 +0,0 @@
{
"name": "Address",
"base": "PersistedModel",
"validateUpsert": true,
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"clientFk": {
"type": "Number"
},
"consignee": {
"type": "string",
"required": true
},
"street": {
"type": "string",
"required": true
},
"city": {
"type": "string",
"required": true
},
"postcode": {
"type": "string"
},
"provinceFk": {
"type": "Number"
},
"phone": {
"type": "string"
},
"mobile": {
"type": "string"
},
"enabled": {
"type": "boolean"
},
"default": {
"type": "boolean"
},
"defaultAgencyFk": {
"type": "Number"
},
"longitude": {
"type": "Number"
},
"latitude": {
"type": "Number"
}
},
"validations": [],
"relations": {
"countryFk": {
"type": "hasOne",
"model": "Country",
"foreignKey": "id"
},
"clientFk": {
"type": "hasOne",
"model": "Client",
"foreignKey": "id"
},
"defaultAgencyFk": {
"type": "hasOne",
"model": "Agency",
"foreignKey": "id"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -1,145 +0,0 @@
module.exports = function(Client) {
// Validations
Client.validatesUniquenessOf('name', {message: 'El nombre debe ser único'});
Client.validatesUniquenessOf('fi', {message: 'El NIF/CIF debe ser único'});
Client.validatesPresenceOf('socialName', {message: 'Debe especificarse la razón social'});
Client.validatesFormatOf('postcode', {allowNull: true, with: /^\d+$/, message: 'El código postal solo debe contener números'});
Client.validatesLengthOf('postcode', {allowNull: true, min: 3, max: 10});
Client.validatesFormatOf('email', {allowNull: true, with: /^[\w|\.|\-]+@\w[\w|\.|\-]*\w$/, message: 'Correo electrónico inválido'});
Client.validate('payMethod', hasCC, {message: 'Introduzca el iban del cliente'});
function hasCC(err) {
if (this.payMethod == 2 && !this.iban) err();
};
Client.validate('payMethod', hasSalesMan, {message: 'No se puede cambiar la forma de pago si no hay comercial asignado'});
function hasSalesMan(err) {
if(this.payMethod && !this.salesPerson) err();
};
// Hooks
Client.observe('before save', function(ctx, next) {
if(ctx.instance) {
if (!ctx.instance.dueDay){
ctx.instance.dueDay = 5;
}
next();
}
else {
Client.findById(ctx.where.id,
function(err, item) {
if (!err) {
if (item.payMethod != ctx.data.payMethod && item.dueDay == ctx.data.dueDay) {
ctx.data.dueDay = 5;
}
}
next();
}
);
}
});
// 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
Client.installMethod('filter', filterClients);
function filterClients(p) {
return {
where: {
id: p.id,
name: {regexp: p.name},
cif: p.cif,
socialName: {regexp: p.socialName},
city: {regexp: p.city},
postcode: p.postcode,
email: {regexp: p.email},
phone: p.phone
},
skip: (p.page - 1) * p.size,
limit: p.size
};
}
// 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);
}
})
};
};

View File

@ -1,163 +0,0 @@
{
"name": "Client",
"base": "MyModel",
"scopes": {
"test": {
"where": {
"name": "Verdnatura"
}
}
},
"validateUpsert": true,
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string",
"required": true
},
"fi": {
"type": "string",
"description": "Fiscal indetifier"
},
"socialName": {
"type": "string"
},
"creationTime": {
"type": "string"
},
"contact": {
"type": "string"
},
"street": {
"type": "string"
},
"city": {
"type": "string"
},
"postcode": {
"type": "string"
},
"provinceFk": {
"type": "Number"
},
"countryFk": {
"type": "Number"
},
"email": {
"type": "string"
},
"phone": {
"type": "string"
},
"mobile": {
"type": "string"
},
"fax": {
"type": "string"
},
"active": {
"type": "boolean"
},
"credit": {
"type": "Number"
},
"creditInsurance": {
"type": "Number"
},
"iban": {
"type": "string"
},
"dueDay": {
"type": "Number"
},
"equalizationTax": {
"type": "boolean",
"description": "The client has equalization tax"
},
"hasToInvoice": {
"type": "boolean",
"description": "Global invoicing enabled for the client"
},
"invoiceByEmail": {
"type": "boolean",
"description": "Send invoices by email"
},
"payMethodFk": {
"type": "Number"
},
"salesPersonFk": {
"type": "Number"
},
"contactChannelFk": {
"type": "Number"
},
"sepaVnl": {
"type": "boolean"
},
"coreVnl": {
"type": "boolean"
},
"coreVnh": {
"type": "boolean"
},
"eypbc": {
"type": "boolean"
},
"quality": {
"type": "Number"
},
"vies": {
"type": "Number"
},
"isRelevant": {
"type": "boolean"
},
"typeFk": {
"type": "Number"
},
"accountingAccount": {
"type": "string"
}
},
"validations": [],
"relations": {
"accountFk": {
"type": "hasOne",
"model": "Account",
"foreignKey": "id"
},
"payMethodFk": {
"type": "hasOne",
"model": "PayMethod",
"foreignKey": "id"
},
"salesPersonFk": {
"type": "hasOne",
"model": "Employee",
"foreignKey": "id"
},
"addressesFk": {
"type": "hasMany",
"model": "Address",
"foreignKey": "clientFk"
},
"chanelFK":{
"type": "hasOne",
"model": "Chanel",
"foreignKey": "chanelFK"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
],
"methods": {}
}

View File

@ -1,36 +0,0 @@
{
"name": "Country",
"base": "PersistedModel",
"validateUpsert": true,
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string",
"required": true
},
"inCee": {
"type": "Number"
},
"code": {
"type": "string"
},
"currencyFk": {
"type": "Number"
},
"realCountryFk": {
"type": "Number"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -1,28 +0,0 @@
{
"name": "Employee",
"base": "PersistedModel",
"validateUpsert": true,
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string",
"required": true
},
"userFk": {
"type": "Number",
"required": true
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -1,40 +0,0 @@
{
"name": "Province",
"base": "PersistedModel",
"validateUpsert": true,
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string",
"required": true
},
"countryFk": {
"type": "Number"
},
"warehouseFk": {
"type": "Number"
},
"zoneFk": {
"type": "Number"
}
},
"relations": {
"countryFk": {
"type": "hasOne",
"model": "Country",
"foreignKey": "id"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

BIN
services/production/.DS_Store vendored Normal file

Binary file not shown.