From ce2d7936afb2a6a12a0b73d2e01138d5efb453be Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 28 Apr 2017 15:04:29 +0200 Subject: [PATCH] =?UTF-8?q?Integraci=C3=B3n=20con=20MySQL,=20errores=20sol?= =?UTF-8?q?ucionados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + client/client/src/basic-data/index.html | 2 +- client/client/src/fiscal-data/index.html | 2 +- client/core/src/autocomplete/index.js | 3 +- client/core/src/card/card.js | 2 +- client/core/src/components.js | 3 +- client/core/src/directives/validation.js | 30 +++++--- client/core/src/filters/index.js | 2 +- client/core/src/filters/phone.js | 10 +-- client/core/src/icon/index.js | 6 +- client/core/src/lib/component.js | 11 ++- client/core/src/lib/inputAttrsNormalizer.js | 10 +-- client/core/src/textfield/index.js | 69 +++++++++++++++++++ .../{textfield.mdl.html => index.mdl.html} | 7 +- client/core/src/textfield/index.mdl.js | 16 +++++ client/core/src/textfield/style.css | 11 --- client/core/src/textfield/style.scss | 12 ++++ client/core/src/textfield/textfield.js | 59 ---------------- client/core/src/textfield/textfield.mdl.js | 24 ------- db.json | 5 +- services/auth/package.json | 7 +- services/auth/server/boot/createmodel.js | 2 + services/auth/server/boot/root.js | 1 - services/auth/server/datasources.json | 12 +++- services/auth/server/model-config.json | 20 ++++-- services/client/common/models/Address.json | 11 +-- services/client/common/models/Client.js | 4 +- services/client/common/models/Client.json | 21 ++++-- .../common/models/ClientObservation.json | 6 +- .../{SalesPerson.json => Employee.json} | 2 +- .../{PaymentMethod.json => PayMethod.json} | 2 +- services/client/common/models/Province.json | 7 ++ services/client/package.json | 1 + services/client/server/boot/authentication.js | 2 +- services/client/server/boot/root.js | 9 ++- services/client/server/datasources.json | 20 ++++++ services/client/server/model-config.json | 32 ++++----- 37 files changed, 269 insertions(+), 175 deletions(-) create mode 100644 client/core/src/textfield/index.js rename client/core/src/textfield/{textfield.mdl.html => index.mdl.html} (63%) create mode 100644 client/core/src/textfield/index.mdl.js delete mode 100644 client/core/src/textfield/style.css create mode 100644 client/core/src/textfield/style.scss delete mode 100644 client/core/src/textfield/textfield.js delete mode 100644 client/core/src/textfield/textfield.mdl.js rename services/client/common/models/{SalesPerson.json => Employee.json} (93%) rename services/client/common/models/{PaymentMethod.json => PayMethod.json} (93%) diff --git a/.gitignore b/.gitignore index d3afec1d95..13438391d5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ spliting.js build npm-debug.log debug.log +datasources.development.json diff --git a/client/client/src/basic-data/index.html b/client/client/src/basic-data/index.html index dc42472f72..b8b5e1ee91 100644 --- a/client/client/src/basic-data/index.html +++ b/client/client/src/basic-data/index.html @@ -23,7 +23,7 @@ diff --git a/client/client/src/fiscal-data/index.html b/client/client/src/fiscal-data/index.html index 867ac8f54d..767c2d817d 100644 --- a/client/client/src/fiscal-data/index.html +++ b/client/client/src/fiscal-data/index.html @@ -43,7 +43,7 @@ diff --git a/client/core/src/autocomplete/index.js b/client/core/src/autocomplete/index.js index 09c9c35352..3cd5cdb698 100644 --- a/client/core/src/autocomplete/index.js +++ b/client/core/src/autocomplete/index.js @@ -3,8 +3,7 @@ import Component from '../lib/component'; import './style.scss'; /** - * Combobox like component with search and partial data loading - * features. + * Combobox like component with search and partial data loading features. */ export default class Autocomplete extends Component { constructor($element, $scope, $http, vnPopover) { diff --git a/client/core/src/card/card.js b/client/core/src/card/card.js index d32db77a26..50aad3a2bb 100644 --- a/client/core/src/card/card.js +++ b/client/core/src/card/card.js @@ -1,7 +1,7 @@ import {module as _module} from '../module'; import * as resolveFactory from '../lib/resolveDefaultComponents'; import * as util from '../lib/util'; -require ('./style.css'); +require('./style.css'); const _NAME = 'card'; export const NAME = util.getName(_NAME); diff --git a/client/core/src/components.js b/client/core/src/components.js index c0aaf15475..7a258fd3be 100644 --- a/client/core/src/components.js +++ b/client/core/src/components.js @@ -1,6 +1,7 @@ import './mdl-override.css'; import './styles/fonts/mdi-override.css'; +import './textfield/index'; import './watcher/index'; import './paging/index'; import './icon/index'; @@ -20,8 +21,6 @@ export {NAME as RADIO, directive as RadioDirective} from './radio/radio'; export {NAME as RADIO_MDL, factory as radionMdl} from './radio/radio.mdl'; export {NAME as TEXTAREA, directive as TextareaDirective} from './textarea/textarea'; export {NAME as TEXTAREA_MDL, factory as textareaMdl} from './textarea/textarea.mdl'; -export {NAME as TEXTFIELD, directive as TextfieldDirective} from './textfield/textfield'; -export {NAME as TEXTFIELD_MDL, factory as textfieldMdl} from './textfield/textfield.mdl'; export {NAME as LABEL, directive as LabelDirective} from './label/label'; export {NAME as LABEL_MDL, factory as labelMdl} from './label/label.mdl'; export {NAME as ICON_BUTTON, directive as IconButtonDirective} from './icon-button/icon-button'; diff --git a/client/core/src/directives/validation.js b/client/core/src/directives/validation.js index 943f117979..0b0939318a 100644 --- a/client/core/src/directives/validation.js +++ b/client/core/src/directives/validation.js @@ -33,20 +33,19 @@ export function directive(interpolate, compile, $window) { if (!validations || validations.length == 0) return; - let errorMsg = angular.element(''); - element.after(errorMsg); - let input = ctrl[0]; let form = ctrl[1]; - let parent = element.parent(); + let errorSpan = angular.element(''); + let errorMsg; + let errorShown = false; input.$validators.entity = function(value) { try { validateAll(value, validations); return true; } catch (e) { - errorMsg.text(e.message); - parent.attr('title', e.message); + errorMsg = e.message; + if (errorShown) changeError(); return false; } }; @@ -54,14 +53,27 @@ export function directive(interpolate, compile, $window) { scope.$watch(function() { return (form.$submitted || input.$dirty) && input.$invalid; }, function(value) { + let parent = element.parent(); + if (value) { + changeError(); parent.addClass('invalid'); - errorMsg[0].style.display = 'block'; - } else { + element.after(errorSpan); + } else if (errorShown) { parent.removeClass('invalid'); - errorMsg[0].style.display = 'none'; + parent.removeAttr('title'); + errorSpan.remove(); + errorSpan.empty(); } + + errorShown = value; }); + + function changeError() { + let parent = element.parent(); + errorSpan.text(errorMsg); + parent.attr('title', errorMsg); + } } } module.directive('vnValidation', directive); diff --git a/client/core/src/filters/index.js b/client/core/src/filters/index.js index 7885919011..de0560b2f8 100644 --- a/client/core/src/filters/index.js +++ b/client/core/src/filters/index.js @@ -1 +1 @@ -import './phone'; \ No newline at end of file +import './phone'; diff --git a/client/core/src/filters/phone.js b/client/core/src/filters/phone.js index a00b9a3d9b..3146e24c10 100644 --- a/client/core/src/filters/phone.js +++ b/client/core/src/filters/phone.js @@ -2,15 +2,17 @@ import {module} from '../module'; /** * Formats a phone number putting a space every three digits. + * + * @return {String} The formated number */ export default function phone() { return function(input) { input = input || ''; let out = ''; - for(let i = 0; i < input.length; i++) { - out = out + input.charAt(i); - if((i+1) % 3 == 0) - out = out +' '; + for (let i = 0; i < input.length; i++) { + out += input.charAt(i); + if ((i + 1) % 3 == 0) + out += ' '; } return out; }; diff --git a/client/core/src/icon/index.js b/client/core/src/icon/index.js index 9ed9558d55..7e36fab97f 100644 --- a/client/core/src/icon/index.js +++ b/client/core/src/icon/index.js @@ -1,7 +1,7 @@ import {module} from '../module'; -export {factory as mdlFactory} from './index.mdl'; +import './index.mdl'; +import './style.css'; import * as resolveFactory from '../lib/resolveDefaultComponents'; -require('./style.css'); const _NAME = 'icon'; export const NAME = 'vnIcon'; @@ -12,7 +12,7 @@ export function directive(resolver) { template: function(_, attrs) { return resolver.getTemplate(_NAME, attrs); } - } + }; } directive.$inject = [resolveFactory.NAME]; diff --git a/client/core/src/lib/component.js b/client/core/src/lib/component.js index 9709b97db1..2d8d689cc6 100644 --- a/client/core/src/lib/component.js +++ b/client/core/src/lib/component.js @@ -3,20 +3,25 @@ */ export default class Component { /** - * The element window. + * The component owner window. */ get window() { return this.document.defaultView; } + /** + * The component owner document. + */ + get document() { + return this.element.ownerDocument; + } /** * Contructor. - * + * * @param {HTMLElement} $element The main component element */ constructor($element) { this.element = $element[0]; this.element.$ctrl = this; - this.document = $element[0].ownerDocument; } } Component.$inject = ['$element']; diff --git a/client/core/src/lib/inputAttrsNormalizer.js b/client/core/src/lib/inputAttrsNormalizer.js index 10d0573706..355d268b92 100644 --- a/client/core/src/lib/inputAttrsNormalizer.js +++ b/client/core/src/lib/inputAttrsNormalizer.js @@ -3,14 +3,14 @@ import {module} from '../module'; export const NAME = 'vnInputAttrsNormalizer'; export class InputAttrsNormalizer { normalize(attrs) { - if(attrs.field) { + if (attrs.field) { let split = attrs.field.split('.'); let len = split.length; - if(len == 0) - throw new Error (`Attribute 'field' can not be empty`); - if(len > 3) - throw new Error (`Attribute 'field' must have this syntax: [ctrl].[entity].[field]`); + if (len == 0) + throw new Error(`Attribute 'field' can not be empty`); + if (len > 3) + throw new Error(`Attribute 'field' must have this syntax: [ctrl].[entity].[field]`); let i = len - 1; let field = split[i--]; diff --git a/client/core/src/textfield/index.js b/client/core/src/textfield/index.js new file mode 100644 index 0000000000..2c600b74bd --- /dev/null +++ b/client/core/src/textfield/index.js @@ -0,0 +1,69 @@ +import {module} from '../module'; +import Component from '../lib/component'; +import * as resolveFactory from '../lib/resolveDefaultComponents'; +import * as normalizerFactory from '../lib/inputAttrsNormalizer'; +import './style.scss'; +import './index.mdl'; + +export default class Textfield extends Component { + constructor($element, $scope, $attrs) { + super($element); + + let input = this.input = this.element.querySelector('input'); + input.addEventListener('input', + () => this.checkValue()); + input.addEventListener('focus', + () => this.checkValue()); + input.addEventListener('blur', + () => this.showClear(false)); + + let clearButton = this.element.querySelector('button'); + clearButton.addEventListener('click', + () => this.onClearClick()); + clearButton.addEventListener('mousedown', + event => event.preventDefault()); + + // input.value = ' '; + let div = this.element.firstChild; + componentHandler.upgradeElement(div); + } + link($scope, $attrs) { + let mdlTextField = this.element.firstChild.MaterialTextfield; + $scope.$watch($attrs.model, + () => mdlTextField.updateClasses_()); + mdlTextField.updateClasses_(); + } + onClearClick() { + this.input.value = ''; + this.checkValue(); + + let event = this.document.createEvent('HTMLEvents'); + event.initEvent('change', false, true); + this.input.dispatchEvent(event); + } + checkValue() { + this.showClear(this.input.value); + } + showClear(show) { + let clearButton = this.element.querySelector('button'); + clearButton.style.visibility = show ? 'visible' : 'hidden'; + } +} +Textfield.$inject = ['$element', '$scope', '$attrs']; + +directive.$inject = [resolveFactory.NAME, normalizerFactory.NAME]; +export function directive(resolve, normalizer) { + return { + restrict: 'E', + template: function(_, attrs) { + normalizer.normalize(attrs); + return resolve.getTemplate('textfield', attrs); + }, + link: function($scope, $element, $attrs, $ctrl) { + $ctrl.link($scope, $attrs); + }, + controller: Textfield + }; +} + +module.directive('vnTextfield', directive); diff --git a/client/core/src/textfield/textfield.mdl.html b/client/core/src/textfield/index.mdl.html similarity index 63% rename from client/core/src/textfield/textfield.mdl.html rename to client/core/src/textfield/index.mdl.html index c423a596cb..f697c87905 100644 --- a/client/core/src/textfield/textfield.mdl.html +++ b/client/core/src/textfield/index.mdl.html @@ -5,11 +5,8 @@ name="*[name]*" ng-model="*[model]*" vn-validation="*[rule]*" - *[enabled]* - ng-focus="onFocusInput(*[model]*, $event)" - ng-blur="onBlurInput($event)" - /> - diff --git a/client/core/src/textfield/index.mdl.js b/client/core/src/textfield/index.mdl.js new file mode 100644 index 0000000000..64e156885f --- /dev/null +++ b/client/core/src/textfield/index.mdl.js @@ -0,0 +1,16 @@ +import {module} from '../module'; + +export const NAME = 'vnTextfieldMdlFactory'; + +export function factory() { + return { + template: require('./index.mdl.html'), + default: { + label: 'text', + className: 'mdl-textfield--floating-label', + type: 'text' + } + }; +} + +module.factory(NAME, factory); diff --git a/client/core/src/textfield/style.css b/client/core/src/textfield/style.css deleted file mode 100644 index 78137af7ce..0000000000 --- a/client/core/src/textfield/style.css +++ /dev/null @@ -1,11 +0,0 @@ -.mdl-chip__action{ - position: absolute; - top: 0px; - right: -6px; - margin: 22px 0px; - visibility: hidden; -} - -.material-icons{ - font-size: 18px; -} \ No newline at end of file diff --git a/client/core/src/textfield/style.scss b/client/core/src/textfield/style.scss new file mode 100644 index 0000000000..006d8bbd28 --- /dev/null +++ b/client/core/src/textfield/style.scss @@ -0,0 +1,12 @@ +vn-textfield { + .mdl-chip__action{ + position: absolute; + top: 0px; + right: -6px; + margin: 22px 0px; + visibility: hidden; + } + .material-icons{ + font-size: 18px; + } +} \ No newline at end of file diff --git a/client/core/src/textfield/textfield.js b/client/core/src/textfield/textfield.js deleted file mode 100644 index 09a61ead97..0000000000 --- a/client/core/src/textfield/textfield.js +++ /dev/null @@ -1,59 +0,0 @@ -import {module as _module} from '../module'; -import * as resolveFactory from '../lib/resolveDefaultComponents'; -import * as normalizerFactory from '../lib/inputAttrsNormalizer'; -import * as util from '../lib/util'; -require('./style.css'); - -const _NAME = 'textfield'; -export const NAME = util.getName(_NAME); - -directive.$inject = [resolveFactory.NAME, normalizerFactory.NAME, '$parse']; -export function directive(resolve, normalizer, $parse) { - return { - restrict: 'E', - template: function(_, attrs) { - normalizer.normalize(attrs); - return resolve.getTemplate(_NAME, attrs); - }, - link: function(scope, element, attrs) { - scope.$watch(attrs.model, () => { - let mdlField = element[0].firstChild.MaterialTextfield; - if (mdlField) - mdlField.updateClasses_(); - }); - componentHandler.upgradeElement(element[0].firstChild); - - scope.clickClear = function(model) { - setTimeout(() => { - scope.$apply(function() { - $parse(model).assign(scope, ""); - }); - }); - }; - scope.onFocusInput = function(model, event) { - var buttonClear = event.target.parentNode.querySelector("button"); - checkModelValue(buttonClear, model); - }; - scope.onBlurInput = function(event) { - var buttonClear = event.target.parentNode.querySelector("button"); - setTimeout(() => { - buttonClear.style.visibility = "hidden"; - }, 80); - }; - element.on('input', function() { - var buttonClear = this.querySelector("button"); - var model = this.querySelector("input").value; - checkModelValue(buttonClear, model); - }); - - function checkModelValue(buttonClear, model) { - if (model !== undefined && model !== "") - buttonClear.style.visibility = "visible"; - else - buttonClear.style.visibility = "hidden"; - } - } - }; -} - -_module.directive(NAME, directive); diff --git a/client/core/src/textfield/textfield.mdl.js b/client/core/src/textfield/textfield.mdl.js deleted file mode 100644 index 59831301a0..0000000000 --- a/client/core/src/textfield/textfield.mdl.js +++ /dev/null @@ -1,24 +0,0 @@ -import {module as _module} from '../module'; -import * as util from '../lib/util'; -import * as constant from '../lib/constants'; -import template from './textfield.mdl.html'; - -const _NAME = 'textfield'; -const DEFAULT_LABEL = 'text'; -const DEFAULT_CLASS = 'mdl-textfield--floating-label'; -const DEFAULT_TYPE = 'text'; - -export const NAME = util.getFactoryName(_NAME + constant.MATERIAL_DESIGN_FRAMEWORK); - -export function factory() { - return { - template: template, - default: { - label: DEFAULT_LABEL, - className: DEFAULT_CLASS, - type: DEFAULT_TYPE - } - }; -} - -_module.factory(NAME, factory); diff --git a/db.json b/db.json index 80c2dac85f..bd1d89d1fa 100644 --- a/db.json +++ b/db.json @@ -2,7 +2,7 @@ "ids": { "User": 2, "AccessToken": 4, - "Client": 23, + "Client": 24, "PaymentMethod": 4, "SalesPerson": 11, "Address": 87, @@ -28,7 +28,8 @@ "16": "{\"name\":\"Floristeria Antonieta\",\"fi\":\"2345234523d\",\"socialName\":\"23452345assdfgsdfgt\",\"active\":true,\"dueDay\":5,\"id\":16,\"modify\":\"FiscalData\",\"email\":\"antonieta@gmail.com\",\"phone\":\"654654654\",\"mobile\":\"654456456\",\"fax\":\"456456456\",\"street\":\"asdfasdf\",\"salesPerson\":8,\"city\":\"Albalat de la Ribera\",\"postcode\":\"46532\"}", "19": "{\"name\":\"Planticas Eustaquio\",\"fi\":\"789456123B\",\"socialName\":\"Eustaquio Martinez\",\"active\":true,\"dueDay\":5,\"id\":19,\"email\":\"peustaquio@hotmail.es\",\"city\":\"Polinya\",\"postcode\":\"46231\",\"phone\":\"963215486\"}", "21": "{\"name\":\"Ramos Antonieta\",\"fi\":\"B89564289\",\"socialName\":\"Antonia SL\",\"active\":true,\"dueDay\":5,\"id\":21,\"email\":\"ramos@rantonieta.es\",\"salesPerson\":8,\"phone\":\"986574232\"}", - "22": "{\"name\":\"Plantas Raimundo\",\"fi\":\"2536418B\",\"socialName\":\"Plantas Raimundo SL\",\"dueDay\":5,\"id\":22,\"email\":\"jose@plantasraimundo.com\",\"phone\":\"963254289\",\"mobile\":\"641967586\",\"salesPerson\":3,\"city\":\"Sueca\",\"postcode\":\"46985\"}" + "22": "{\"name\":\"Plantas Raimundo\",\"fi\":\"2536418B\",\"socialName\":\"Plantas Raimundo SL\",\"dueDay\":5,\"id\":22,\"email\":\"jose@plantasraimundo.com\",\"phone\":\"963254289\",\"mobile\":\"641967586\",\"salesPerson\":3,\"city\":\"Sueca\",\"postcode\":\"46985\"}", + "23": "{\"name\":\"ddddddddd\",\"fi\":\"sdsdsd\",\"socialName\":\"sdsdsd\",\"dueDay\":5,\"id\":23}" }, "PaymentMethod": { "1": "{\"name\":\"Tarjeta\",\"id\":1}", diff --git a/services/auth/package.json b/services/auth/package.json index 5389e29d35..372b00e70b 100644 --- a/services/auth/package.json +++ b/services/auth/package.json @@ -11,12 +11,13 @@ "compression": "^1.0.3", "cors": "^2.5.2", "helmet": "^1.3.0", + "loopback": "^2.22.0", "loopback-boot": "^2.6.5", "loopback-component-explorer": "^2.4.0", - "serve-favicon": "^2.0.1", - "strong-error-handler": "^1.0.1", + "loopback-connector-mysql": "^3.0.0", "loopback-datasource-juggler": "^2.39.0", - "loopback": "^2.22.0" + "serve-favicon": "^2.0.1", + "strong-error-handler": "^1.0.1" }, "devDependencies": { "eslint": "^2.13.1", diff --git a/services/auth/server/boot/createmodel.js b/services/auth/server/boot/createmodel.js index 94ba11859b..1a25759e24 100644 --- a/services/auth/server/boot/createmodel.js +++ b/services/auth/server/boot/createmodel.js @@ -1,7 +1,9 @@ module.exports = function(app) { +/* var User = app.models.User; User.create ({ email: 'admin@admin.com', password: '1234' }, function (err, user) {}); +*/ }; diff --git a/services/auth/server/boot/root.js b/services/auth/server/boot/root.js index 22eedaa99a..3ca07fb25f 100644 --- a/services/auth/server/boot/root.js +++ b/services/auth/server/boot/root.js @@ -1,4 +1,3 @@ -'use strict'; module.exports = function(server) { // Install a `/` route that returns server status diff --git a/services/auth/server/datasources.json b/services/auth/server/datasources.json index e21dd4db4c..12a0c19464 100644 --- a/services/auth/server/datasources.json +++ b/services/auth/server/datasources.json @@ -1,6 +1,16 @@ { -"db": { + "db": { "name": "db", "connector": "memory" + }, + "auth": { + "name": "mysql", + "connector": "mysql", + "database": "auth", + "debug": false, + "host": "localhost", + "port": 3306, + "username": "root", + "password": "" } } diff --git a/services/auth/server/model-config.json b/services/auth/server/model-config.json index cd7a2d8553..45d293eb7f 100644 --- a/services/auth/server/model-config.json +++ b/services/auth/server/model-config.json @@ -14,12 +14,24 @@ ] }, "User": { - "dataSource": "db", - "public": false + "dataSource": "auth", + "public": true }, "AccessToken": { - "dataSource": "db", - "public": false, + "dataSource": "auth", + "public": true, "strict": true + }, + "ACL": { + "dataSource": "auth", + "public": true + }, + "RoleMapping": { + "dataSource": "auth", + "public": true + }, + "Role": { + "dataSource": "auth", + "public": true } } \ No newline at end of file diff --git a/services/client/common/models/Address.json b/services/client/common/models/Address.json index 8b60a44b26..7c6d9cc090 100644 --- a/services/client/common/models/Address.json +++ b/services/client/common/models/Address.json @@ -8,11 +8,11 @@ "id": true, "description": "Identifier" }, - "street": { + "consignee": { "type": "string", "required": true }, - "consignee": { + "street": { "type": "string", "required": true }, @@ -23,8 +23,8 @@ "postcode": { "type": "string" }, - "enabled": { - "type": "boolean" + "province": { + "type": "Number" }, "phone": { "type": "string" @@ -32,6 +32,9 @@ "mobile": { "type": "string" }, + "enabled": { + "type": "boolean" + }, "default": { "type": "boolean" } diff --git a/services/client/common/models/Client.js b/services/client/common/models/Client.js index 64f7fa60fb..c6e37c61d4 100644 --- a/services/client/common/models/Client.js +++ b/services/client/common/models/Client.js @@ -2,8 +2,8 @@ module.exports = function(Client) { // Validations - Client.validatesUniquenessOf('name', {message: 'El nombre debe ser unico'}); - Client.validatesUniquenessOf('fi', {message: 'El nif/cif debe ser unico'}); + 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}); diff --git a/services/client/common/models/Client.json b/services/client/common/models/Client.json index 55ce4d0704..e45d835765 100644 --- a/services/client/common/models/Client.json +++ b/services/client/common/models/Client.json @@ -35,12 +35,15 @@ "street": { "type": "string" }, - "consignee": { - "type": "string" - }, "city": { "type": "string" }, + "province": { + "type": "Number" + }, + "country": { + "type": "Number" + }, "postcode": { "type": "string" }, @@ -71,7 +74,7 @@ "dueDay": { "type": "Number" }, - "gestdoc": { + "dms": { "type": "Number" }, "surcharge": { @@ -94,6 +97,16 @@ "model": "Account", "foreignKey": "id" }, + "payMethod": { + "type": "hasOne", + "model": "PayMethod", + "foreignKey": "id" + }, + "salesPerson": { + "type": "hasOne", + "model": "Employee", + "foreignKey": "id" + }, "addresses": { "type": "hasMany", "model": "Address", diff --git a/services/client/common/models/ClientObservation.json b/services/client/common/models/ClientObservation.json index ec854e32d6..b875c4ce0d 100644 --- a/services/client/common/models/ClientObservation.json +++ b/services/client/common/models/ClientObservation.json @@ -20,11 +20,11 @@ }, "relations": { "salesPerson": { - "type": "belongsTo", - "model": "SalesPerson", + "type": "hasOne", + "model": "Employee", "foreignKey": "id" }, - "clients": { + "client": { "type": "hasOne", "model": "Client", "foreignKey": "id" diff --git a/services/client/common/models/SalesPerson.json b/services/client/common/models/Employee.json similarity index 93% rename from services/client/common/models/SalesPerson.json rename to services/client/common/models/Employee.json index 20c4aa53f0..f8c6421d31 100644 --- a/services/client/common/models/SalesPerson.json +++ b/services/client/common/models/Employee.json @@ -1,5 +1,5 @@ { - "name": "SalesPerson", + "name": "Employee", "base": "PersistedModel", "validateUpsert": true, "properties": { diff --git a/services/client/common/models/PaymentMethod.json b/services/client/common/models/PayMethod.json similarity index 93% rename from services/client/common/models/PaymentMethod.json rename to services/client/common/models/PayMethod.json index 7bf183ad33..ee72073fb6 100644 --- a/services/client/common/models/PaymentMethod.json +++ b/services/client/common/models/PayMethod.json @@ -1,5 +1,5 @@ { - "name": "PaymentMethod", + "name": "PayMethod", "base": "PersistedModel", "validateUpsert": true, "properties": { diff --git a/services/client/common/models/Province.json b/services/client/common/models/Province.json index cced0d368b..9063c249d8 100644 --- a/services/client/common/models/Province.json +++ b/services/client/common/models/Province.json @@ -13,6 +13,13 @@ "required": true } }, + "relations": { + "country": { + "type": "hasOne", + "model": "Country", + "foreignKey": "id" + } + }, "acls": [ { "accessType": "*", diff --git a/services/client/package.json b/services/client/package.json index 3656a4540e..fdcd7ada62 100644 --- a/services/client/package.json +++ b/services/client/package.json @@ -14,6 +14,7 @@ "loopback": "^2.38.0", "loopback-boot": "^2.6.5", "loopback-component-explorer": "^2.7.0", + "loopback-connector-mysql": "^3.0.0", "loopback-datasource-juggler": "^2.54.0", "serve-favicon": "^2.0.1", "strong-error-handler": "^1.2.1" diff --git a/services/client/server/boot/authentication.js b/services/client/server/boot/authentication.js index 9f133a20b6..2cd84e88a6 100644 --- a/services/client/server/boot/authentication.js +++ b/services/client/server/boot/authentication.js @@ -1,4 +1,4 @@ module.exports = function(server) { - server.enableAuth(); + //server.enableAuth(); }; diff --git a/services/client/server/boot/root.js b/services/client/server/boot/root.js index 79b68d7172..151db3f8de 100644 --- a/services/client/server/boot/root.js +++ b/services/client/server/boot/root.js @@ -1,6 +1,13 @@ module.exports = function(server) { - var router = server.loopback.Router(); + let router = server.loopback.Router(); router.get('/status', server.loopback.status()); server.use(router); +/* + let ds = server.dataSources.auth; + //ds.automigrate(function() { + ds.autoupdate(function() { + console.log('Tables migrated!'); + }); +*/ }; diff --git a/services/client/server/datasources.json b/services/client/server/datasources.json index 8adff1558e..782619ed14 100644 --- a/services/client/server/datasources.json +++ b/services/client/server/datasources.json @@ -3,5 +3,25 @@ "name": "db", "connector": "memory", "file": "db.json" + }, + "auth": { + "name": "mysql", + "connector": "mysql", + "database": "auth", + "debug": false, + "host": "localhost", + "port": 3306, + "username": "root", + "password": "" + }, + "vn": { + "name": "mysql", + "connector": "mysql", + "database": "vn", + "debug": false, + "host": "localhost", + "port": 3306, + "username": "root", + "password": "" } } diff --git a/services/client/server/model-config.json b/services/client/server/model-config.json index f2f708f529..4c46458e2b 100644 --- a/services/client/server/model-config.json +++ b/services/client/server/model-config.json @@ -14,60 +14,60 @@ ] }, "User": { - "dataSource": "db", + "dataSource": "auth", "public": true }, "AccessToken": { - "dataSource": "db", + "dataSource": "auth", "public": true, "strict": true }, "ACL": { - "dataSource": "db", + "dataSource": "auth", "public": true }, "RoleMapping": { - "dataSource": "db", + "dataSource": "auth", "public": true }, "Role": { - "dataSource": "db", + "dataSource": "auth", "public": true }, "Client": { - "dataSource": "db", + "dataSource": "vn", "public": true }, - "PaymentMethod": { - "dataSource": "db", + "PayMethod": { + "dataSource": "vn", "public": true }, - "SalesPerson": { - "dataSource": "db", + "Employee": { + "dataSource": "vn", "public": true }, "Address": { - "dataSource": "db", + "dataSource": "vn", "public": true }, "Agency": { - "dataSource": "db", + "dataSource": "vn", "public": true }, "Province": { - "dataSource": "db", + "dataSource": "vn", "public": true }, "Country": { - "dataSource": "db", + "dataSource": "vn", "public": true }, "ClientObservation": { - "dataSource": "db", + "dataSource": "vn", "public": true }, "Account": { - "dataSource": "db", + "dataSource": "vn", "public": true } }