From c036c7c7fe10c582d8c584d654ec46dbd5b4b527 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 31 Mar 2021 07:33:00 +0200 Subject: [PATCH 1/5] model ok --- db/changes/10300-newFacility/.keep | 1 - .../00-supplierBeneficiary.sql | 2 ++ .../supplier/back/models/supplier-account.json | 17 +---------------- modules/supplier/front/account/index.html | 4 ++++ modules/supplier/front/account/locale/es.yml | 3 ++- 5 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 db/changes/10300-newFacility/.keep create mode 100644 db/changes/10300-newFacility/00-supplierBeneficiary.sql diff --git a/db/changes/10300-newFacility/.keep b/db/changes/10300-newFacility/.keep deleted file mode 100644 index 3ece1d69e..000000000 --- a/db/changes/10300-newFacility/.keep +++ /dev/null @@ -1 +0,0 @@ -Delete this \ No newline at end of file diff --git a/db/changes/10300-newFacility/00-supplierBeneficiary.sql b/db/changes/10300-newFacility/00-supplierBeneficiary.sql new file mode 100644 index 000000000..6dadf16c2 --- /dev/null +++ b/db/changes/10300-newFacility/00-supplierBeneficiary.sql @@ -0,0 +1,2 @@ +ALTER TABLE `supplierAccount` ADD `beneficiary` VARCHAR(50) NULL DEFAULT NULL AFTER `bankFk`; +UPDATE supplierAccount SET beneficiary = `description`; diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index 1d989cbfb..aaab38369 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -22,26 +22,11 @@ "iban": { "type": "String" }, - "office": { - "type": "String" - }, - "DC": { - "type": "String" - }, - "number": { - "type": "String" - }, - "description": { - "type": "String" - }, - "bicSufix": { + "beneficiary": { "type": "String" }, "bankEntityFk": { "type": "Number" - }, - "bankFk": { - "type": "Number" } }, "relations": { diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html index 577fa4e87..be3c6e8be 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -35,6 +35,10 @@ ng-click="$ctrl.showBankEntity($event, $index)"> + + Date: Thu, 1 Apr 2021 17:36:27 +0200 Subject: [PATCH 2/5] reviso test --- .../supplier/back/models/supplier-account.js | 22 +++++++++++++++++++ .../back/models/supplier-account.json | 8 +------ modules/supplier/front/account/index.html | 11 +++++----- modules/supplier/front/account/locale/en.yml | 1 + modules/supplier/front/account/locale/es.yml | 3 ++- 5 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 modules/supplier/back/models/supplier-account.js create mode 100644 modules/supplier/front/account/locale/en.yml diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js new file mode 100644 index 000000000..9d6f10e3c --- /dev/null +++ b/modules/supplier/back/models/supplier-account.js @@ -0,0 +1,22 @@ +const validateIban = require('vn-loopback/util/validateIban'); + +module.exports = Self => { + Self.validateAsync('iban', ibanNeedsValidation, { + message: 'The IBAN does not have the correct format' + }); + + async function ibanNeedsValidation(err, done) { + let filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + let country = await Self.app.models.Country.findOne(filter); + let code = country ? country.code.toLowerCase() : null; + if (code != 'es') + return done(); + + if (!validateIban(this.iban)) + err(); + done(); + } +}; diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index aaab38369..ffd2994ba 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -16,24 +16,18 @@ "id": true, "description": "Identifier" }, - "supplierFk": { - "type": "Number" - }, "iban": { "type": "String" }, "beneficiary": { "type": "String" - }, - "bankEntityFk": { - "type": "Number" } }, "relations": { "supplier": { "type": "belongsTo", "model": "Supplier", - "foreignKey": "supplierFk" + "foreignKey": "supplierFk" }, "bankEntity": { "type": "belongsTo", diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html index be3c6e8be..7264f6f2c 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -1,7 +1,7 @@ -
+ - - + ng-model="supplierAccount.beneficiary" + info="Beneficiary information"> Date: Thu, 1 Apr 2021 18:38:40 +0200 Subject: [PATCH 3/5] test --- .../models/specs/supplier-account.spec.js | 66 +++++++++++++++++++ .../back/models/specs/supplier.spec.js | 2 +- .../back/models/supplier-account.json | 2 +- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 modules/supplier/back/models/specs/supplier-account.spec.js diff --git a/modules/supplier/back/models/specs/supplier-account.spec.js b/modules/supplier/back/models/specs/supplier-account.spec.js new file mode 100644 index 000000000..438b87f8c --- /dev/null +++ b/modules/supplier/back/models/specs/supplier-account.spec.js @@ -0,0 +1,66 @@ +const app = require('vn-loopback/server/server'); +const LoopBackContext = require('loopback-context'); + +describe('loopback model Supplier-account', () => { + describe('create', () => { + const supplierId = 1; + const bankEntityId = 2100; + it('should throw an error when attempting to set an invalid iban account', async() => { + let error; + const expectedError = 'The IBAN does not have the correct format'; + const iban = 'incorrect format'; + // si falla el error es extraño preguntar a carlos + + await app.models.SupplierAccount.create( + { + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + } + ).catch(e => { + error = e; + + expect(error.message).toContain(expectedError); + }); + + expect(error).toBeDefined(); + }); + + it('should create a valid supplier account', async() => { + const tx = await app.models.Claim.beginTransaction({}); + try { + const options = {transaction: tx}; + const iban = 'ES91 2100 0418 4502 0005 1332'; + + const activeCtx = { + accessToken: {userId: 5}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + activeCtx.http.req.__ = value => { + return value; + }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + const createdSupplierAccount = await app.models.SupplierAccount.create( + { + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + } + , options); + + expect(createdSupplierAccount.iban).toBe(iban); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + }); +}); diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 1853b1c9a..f7dd15139 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -1,6 +1,6 @@ const app = require('vn-loopback/server/server'); -describe('loopback model address', () => { +describe('loopback model Supplier', () => { let supplierOne; let supplierTwo; diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index ffd2994ba..8e2838fe5 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -7,7 +7,7 @@ }, "options": { "mysql": { - "table": "supplierAccount" + "table": "supplierAccount" } }, "properties": { From 63ec7677c698a46827e94b8092e0f6a9b3b4aa3b Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 1 Apr 2021 18:43:28 +0200 Subject: [PATCH 4/5] test ok --- db/changes/10300-newFacility/00-supplierBeneficiary.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/changes/10300-newFacility/00-supplierBeneficiary.sql b/db/changes/10300-newFacility/00-supplierBeneficiary.sql index 6dadf16c2..fcd5a1e2e 100644 --- a/db/changes/10300-newFacility/00-supplierBeneficiary.sql +++ b/db/changes/10300-newFacility/00-supplierBeneficiary.sql @@ -1,2 +1,2 @@ -ALTER TABLE `supplierAccount` ADD `beneficiary` VARCHAR(50) NULL DEFAULT NULL AFTER `bankFk`; -UPDATE supplierAccount SET beneficiary = `description`; +ALTER TABLE vn.`supplierAccount` ADD `beneficiary` VARCHAR(50) NULL DEFAULT NULL AFTER `bankFk`; +UPDATE vn.supplierAccount SET beneficiary = `description`; From cd4f93f326024a65368834864f0607dc4f696b60 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 16 Apr 2021 18:35:03 +0200 Subject: [PATCH 5/5] minor fixes --- README.md | 4 ++- .../models/specs/supplier-account.spec.js | 32 +++++++++---------- .../supplier/back/models/supplier-account.js | 4 +-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index da51fe093..32377c115 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,9 @@ Salix is also the scientific name of a beautifull tree! :) Required applications. -* Node.js = 14.15.1 LTS +* Node.js = 14.x LTS +* Docker +* Git * Docker You will need to install globally the following items. diff --git a/modules/supplier/back/models/specs/supplier-account.spec.js b/modules/supplier/back/models/specs/supplier-account.spec.js index 438b87f8c..f56e70a89 100644 --- a/modules/supplier/back/models/specs/supplier-account.spec.js +++ b/modules/supplier/back/models/specs/supplier-account.spec.js @@ -9,19 +9,18 @@ describe('loopback model Supplier-account', () => { let error; const expectedError = 'The IBAN does not have the correct format'; const iban = 'incorrect format'; - // si falla el error es extraño preguntar a carlos - - await app.models.SupplierAccount.create( - { - supplierFk: supplierId, - bankEntityFk: bankEntityId, - iban: iban - } - ).catch(e => { + try { + await app.models.SupplierAccount.create( + { + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + }); + } catch (e) { error = e; expect(error.message).toContain(expectedError); - }); + } expect(error).toBeDefined(); }); @@ -47,13 +46,12 @@ describe('loopback model Supplier-account', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); - const createdSupplierAccount = await app.models.SupplierAccount.create( - { - supplierFk: supplierId, - bankEntityFk: bankEntityId, - iban: iban - } - , options); + const createdSupplierAccount = await app.models.SupplierAccount.create({ + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + }, + options); expect(createdSupplierAccount.iban).toBe(iban); await tx.rollback(); diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js index 9d6f10e3c..85bf37510 100644 --- a/modules/supplier/back/models/supplier-account.js +++ b/modules/supplier/back/models/supplier-account.js @@ -1,11 +1,11 @@ const validateIban = require('vn-loopback/util/validateIban'); module.exports = Self => { - Self.validateAsync('iban', ibanNeedsValidation, { + Self.validateAsync('iban', ibanValidation, { message: 'The IBAN does not have the correct format' }); - async function ibanNeedsValidation(err, done) { + async function ibanValidation(err, done) { let filter = { fields: ['code'], where: {id: this.countryFk}