diff --git a/modules/client/back/methods/address/getAddress.js b/modules/client/back/methods/address/getAddress.js new file mode 100644 index 000000000..94e0439da --- /dev/null +++ b/modules/client/back/methods/address/getAddress.js @@ -0,0 +1,21 @@ +module.exports = Self => { + Self.remoteMethod('getAddress', { + description: 'Get all activated address last year ', + accessType: 'READ', + accepts: [], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/getAddress`, + verb: 'GET' + } + }); + + Self.getAddress = async() => { + const query = `CALL vn.address_getLosesLastYear()`; + const [result] = await Self.rawSql(query); + return result; + }; +}; diff --git a/back/methods/collection/spec/getAddress.spec.js b/modules/client/back/methods/address/specs/getAddress.spec.js similarity index 70% rename from back/methods/collection/spec/getAddress.spec.js rename to modules/client/back/methods/address/specs/getAddress.spec.js index aac769aa3..707d7360b 100644 --- a/back/methods/collection/spec/getAddress.spec.js +++ b/modules/client/back/methods/address/specs/getAddress.spec.js @@ -1,8 +1,8 @@ const {models} = require('vn-loopback/server/server'); -describe('getAddress()', () => { +describe('getAddressa()', () => { fit('return list of address last year', async() => { - let response = await models.Collection.getAddress(); + let response = await models.Addressa.getAddress(); expect(response.length).toBeGreaterThan(0); expect(response[0].addressFk).toEqual(1); diff --git a/modules/client/back/models/address.js b/modules/client/back/models/address.js index 3a1157add..4a93b5d5c 100644 --- a/modules/client/back/models/address.js +++ b/modules/client/back/models/address.js @@ -3,6 +3,8 @@ let getFinalState = require('vn-loopback/util/hook').getFinalState; let isMultiple = require('vn-loopback/util/hook').isMultiple; module.exports = Self => { + require('../methods/address/getAddress')(Self); + Self.validateAsync('isEqualizated', cannotHaveET, { message: 'Cannot check Equalization Tax in this NIF/CIF' });