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/db/changes/10300-newFacility/00-supplierBeneficiary.sql b/db/changes/10300-newFacility/00-supplierBeneficiary.sql new file mode 100644 index 000000000..fcd5a1e2e --- /dev/null +++ b/db/changes/10300-newFacility/00-supplierBeneficiary.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.`supplierAccount` ADD `beneficiary` VARCHAR(50) NULL DEFAULT NULL AFTER `bankFk`; +UPDATE vn.supplierAccount SET beneficiary = `description`; 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..f56e70a89 --- /dev/null +++ b/modules/supplier/back/models/specs/supplier-account.spec.js @@ -0,0 +1,64 @@ +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'; + try { + 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.js b/modules/supplier/back/models/supplier-account.js new file mode 100644 index 000000000..85bf37510 --- /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', ibanValidation, { + message: 'The IBAN does not have the correct format' + }); + + async function ibanValidation(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 1d989cbfb..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": { @@ -16,39 +16,18 @@ "id": true, "description": "Identifier" }, - "supplierFk": { - "type": "Number" - }, "iban": { "type": "String" }, - "office": { + "beneficiary": { "type": "String" - }, - "DC": { - "type": "String" - }, - "number": { - "type": "String" - }, - "description": { - "type": "String" - }, - "bicSufix": { - "type": "String" - }, - "bankEntityFk": { - "type": "Number" - }, - "bankFk": { - "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 577fa4e87..7264f6f2c 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -1,7 +1,7 @@ -
+ - + +