From f3fc211dfa3303207187d55054c547f6af744e9b Mon Sep 17 00:00:00 2001 From: Joan Date: Fri, 31 Aug 2018 07:53:38 +0200 Subject: [PATCH] removed unused routes, filter and crud routes #409 --- client/client/src/filter-client-list.js | 9 -- client/core/src/lib/filter-list.js | 45 -------- client/core/src/lib/index.js | 1 - client/item/src/filter-item-list.js | 9 -- client/item/src/item.js | 1 - client/ticket/src/component/index.html | 14 ++- client/ticket/src/component/index.js | 101 +++++++++++++----- client/ticket/src/component/index.spec.js | 41 +++---- client/ticket/src/filter-ticket-list.js | 9 -- e2e/helpers/nightmare.js | 3 +- .../client-module/04_edit_pay_method.spec.js | 3 + gulpfile.js | 3 + .../client/common/models/client-credit.js | 20 ---- .../methods/item-barcode/crudItemBarcodes.js | 3 - .../spec/crudItemBarcodes.spec.js | 72 ------------- .../methods/item-niche/crudItemNiches.js | 3 - .../item-niche/spec/crudItemNiches.spec.js | 51 --------- services/item/common/models/item-barcode.js | 2 - .../loopback/common/methods/sale/filter.js | 39 ------- .../methods/sale/saleComponentFilter.js | 51 --------- services/loopback/common/models/sale.js | 2 - .../methods/notes/crudTicketObservation.js | 3 - .../common/models/ticket-observation.js | 2 - 23 files changed, 112 insertions(+), 375 deletions(-) delete mode 100644 client/client/src/filter-client-list.js delete mode 100644 client/core/src/lib/filter-list.js delete mode 100644 client/item/src/filter-item-list.js delete mode 100644 client/ticket/src/filter-ticket-list.js delete mode 100644 services/client/common/models/client-credit.js delete mode 100644 services/item/common/methods/item-barcode/crudItemBarcodes.js delete mode 100644 services/item/common/methods/item-barcode/spec/crudItemBarcodes.spec.js delete mode 100644 services/item/common/methods/item-niche/crudItemNiches.js delete mode 100644 services/item/common/methods/item-niche/spec/crudItemNiches.spec.js delete mode 100644 services/loopback/common/methods/sale/filter.js delete mode 100644 services/loopback/common/methods/sale/saleComponentFilter.js delete mode 100644 services/ticket/common/methods/notes/crudTicketObservation.js diff --git a/client/client/src/filter-client-list.js b/client/client/src/filter-client-list.js deleted file mode 100644 index 6e6b007cb..000000000 --- a/client/client/src/filter-client-list.js +++ /dev/null @@ -1,9 +0,0 @@ -import FilterList from 'core/src/lib/filter-list'; - -export default class FilterClientList extends FilterList { - constructor($scope, $timeout, $state) { - super($scope, $timeout, $state); - this.modelName = 'clientFk'; - } -} -FilterClientList.$inject = ['$scope', '$timeout', '$state']; diff --git a/client/core/src/lib/filter-list.js b/client/core/src/lib/filter-list.js deleted file mode 100644 index d3f5d2963..000000000 --- a/client/core/src/lib/filter-list.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Generic class to list models. - */ -export default class FilterList { - constructor($scope, $timeout, $state) { - this.$ = $scope; - this.$timeout = $timeout; - this.$state = $state; - - this.waitingMgCrud = 0; - this.modelId = $state.params.id; - this.instances = []; - } - onOrder(field, order) { - this.filter(`${field} ${order}`); - } - filter(order) { - if (this.$.index && this.modelId && this.modelName) { - this.waitingMgCrud = 0; - this.$.index.filter = { - page: 1, - size: 10 - }; - - this.$.index.filter[this.modelName] = this.modelId; - - if (order) { - this.$.index.filter.order = order; - } - - this.$.index.accept().then(res => { - this.instances = res.instances; - }); - } else if (!this.modelId || !this.modelName) { - throw new Error('Error: model not found'); - } else if (this.waitingMgCrud > 3) { - throw new Error('Error: Magic Crud is not loaded'); - } else { - this.waitingMgCrud++; - this.$timeout(() => { - this.filter(order); - }, 250); - } - } -} diff --git a/client/core/src/lib/index.js b/client/core/src/lib/index.js index 5a43a6988..c2c92457f 100644 --- a/client/core/src/lib/index.js +++ b/client/core/src/lib/index.js @@ -4,7 +4,6 @@ import './app'; import './interceptor'; import './acl-service'; import './storage-services'; -import './filter-list'; import './template'; import './spliting-register'; import './interpolate'; diff --git a/client/item/src/filter-item-list.js b/client/item/src/filter-item-list.js deleted file mode 100644 index e170186bd..000000000 --- a/client/item/src/filter-item-list.js +++ /dev/null @@ -1,9 +0,0 @@ -import FilterList from 'core/src/lib/filter-list'; - -export default class FilterItemList extends FilterList { - constructor($scope, $timeout, $state) { - super($scope, $timeout, $state); - this.modelName = 'itemFk'; - } -} -FilterItemList.$inject = ['$scope', '$timeout', '$state']; diff --git a/client/item/src/item.js b/client/item/src/item.js index e04eef06f..bcbce82fd 100644 --- a/client/item/src/item.js +++ b/client/item/src/item.js @@ -1,7 +1,6 @@ export * from './module'; import './index'; -import './filter-item-list'; import './search-panel'; import './diary'; import './create'; diff --git a/client/ticket/src/component/index.html b/client/ticket/src/component/index.html index fca54dd25..16175048e 100644 --- a/client/ticket/src/component/index.html +++ b/client/ticket/src/component/index.html @@ -1,4 +1,10 @@ - + + @@ -32,7 +38,7 @@ - + {{::sale.quantity * component.value | currency:'€':3}} - + No results - + diff --git a/client/ticket/src/component/index.js b/client/ticket/src/component/index.js index 73a54395f..aa7cb00d9 100644 --- a/client/ticket/src/component/index.js +++ b/client/ticket/src/component/index.js @@ -1,46 +1,89 @@ import ngModule from '../module'; import './style.scss'; -import FilterTicketList from '../filter-ticket-list'; -class Controller extends FilterTicketList { - constructor($scope, $timeout, $stateParams) { - super($scope, $timeout, $stateParams); +class Controller { + constructor($scope, $stateParams) { + this.$stateParams = $stateParams; this.$scope = $scope; - this.onOrder('itemFk', 'ASC'); + this.filter = { + order: 'concept ASC', + include: [{ + relation: 'item', + scope: { + include: { + relation: 'tags', + scope: { + fields: ['tagFk', 'value'], + include: { + relation: 'tag', + scope: { + fields: ['name'] + } + }, + limit: 6 + } + }, + fields: ['itemFk', 'name'] + } + }, + { + relation: 'components', + scope: { + fields: ['componentFk', 'value'], + include: { + relation: 'componentRate', + scope: { + fields: ['componentTypeRate', 'name'], + include: { + relation: 'componentType', + scope: { + fields: ['type'] + } + } + } + } + } + }] + }; } total() { - let sum; - if (this.sales) { - sum = 0; - for (let sale of this.sales) - for (let component of sale.components) - sum += sale.quantity * component.value; - } + let sales = this.$scope.model.data; + let sum = 0; + if (!sales) return; + + for (let sale of sales) + for (let component of sale.components) + sum += sale.quantity * component.value; + return sum; } base() { - let sum; - if (this.sales) { - sum = 0; - for (let sale of this.sales) - for (let component of sale.components) - if (component.componentRate.name == 'valor de compra') - sum += sale.quantity * component.value; - } + let sales = this.$scope.model.data; + let sum = 0; + + if (!sales) return; + + for (let sale of sales) + for (let component of sale.components) + if (component.componentRate.name == 'valor de compra') + sum += sale.quantity * component.value; + return sum; } profitMargin() { - let sum; - if (this.sales) { - sum = 0; - for (let sale of this.sales) - for (let component of sale.components) - if (component.componentRate.name != 'valor de compra') - sum += sale.quantity * component.value; - } + let sales = this.$scope.model.data; + let sum = 0; + + if (!sales) return; + + for (let sale of sales) + for (let component of sale.components) + if (component.componentRate.name != 'valor de compra') + sum += sale.quantity * component.value; + return sum; } @@ -55,7 +98,7 @@ class Controller extends FilterTicketList { } } -Controller.$inject = ['$scope', '$timeout', '$state']; +Controller.$inject = ['$scope', '$stateParams']; ngModule.component('vnTicketComponents', { template: require('./index.html'), diff --git a/client/ticket/src/component/index.spec.js b/client/ticket/src/component/index.spec.js index 083b774e3..94f89d36d 100644 --- a/client/ticket/src/component/index.spec.js +++ b/client/ticket/src/component/index.spec.js @@ -1,41 +1,44 @@ import './index.js'; +import {crudModel} from '../../../helpers/crudModelHelper'; describe('ticket', () => { describe('Component vnTicketComponents', () => { let $componentController; let $state; + let $scope; let controller; beforeEach(() => { angular.mock.module('ticket'); }); - beforeEach(angular.mock.inject((_$componentController_, _$state_) => { + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => { $componentController = _$componentController_; $state = _$state_; $state.params.id = '1'; - controller = $componentController('vnTicketComponents'); + $scope = $rootScope.$new(); + $scope.model = crudModel; + $scope.model.data = [{ + components: [ + {componentRate: {name: 'valor de compra'}, value: 5}, + {componentRate: {name: 'reparto'}, value: 5}, + {componentRate: {name: 'recobro'}, value: 5} + ], + quantity: 1 + }, + { + components: [ + {componentRate: {name: 'valor de compra'}, value: 1}, + {componentRate: {name: 'reparto'}, value: 1}, + {componentRate: {name: 'recobro'}, value: 1} + ], + quantity: 5 + }]; + controller = $componentController('vnTicketComponents', {$scope}); })); describe('total()', () => { it('should return the sum from all componenets in each sale', () => { - controller.sales = [{ - components: [ - {componentRate: {name: 'valor de compra'}, value: 5}, - {componentRate: {name: 'reparto'}, value: 5}, - {componentRate: {name: 'recobro'}, value: 5} - ], - quantity: 1 - }, - { - components: [ - {componentRate: {name: 'valor de compra'}, value: 1}, - {componentRate: {name: 'reparto'}, value: 1}, - {componentRate: {name: 'recobro'}, value: 1} - ], - quantity: 5 - } - ]; let result = controller.total(); expect(result).toEqual(30); diff --git a/client/ticket/src/filter-ticket-list.js b/client/ticket/src/filter-ticket-list.js deleted file mode 100644 index f3a8c801b..000000000 --- a/client/ticket/src/filter-ticket-list.js +++ /dev/null @@ -1,9 +0,0 @@ -import FilterList from 'core/src/lib/filter-list'; - -export default class FilterTicketList extends FilterList { - constructor($scope, $timeout, $state) { - super($scope, $timeout, $state); - this.modelName = 'ticketFk'; - } -} -FilterTicketList.$inject = ['$scope', '$timeout', '$state']; diff --git a/e2e/helpers/nightmare.js b/e2e/helpers/nightmare.js index d18b9d748..c2b7a6515 100644 --- a/e2e/helpers/nightmare.js +++ b/e2e/helpers/nightmare.js @@ -2,7 +2,8 @@ import Nightmare from 'nightmare'; export default function createNightmare(width = 1280, height = 720) { - const nightmare = new Nightmare({show: false, typeInterval: 10, x: 0, y: 0}).viewport(width, height); + const nightmare = new Nightmare({show: process.env.E2E_SHOW, typeInterval: 10, x: 0, y: 0}) + .viewport(width, height); nightmare.on('page', (type, message, error) => { fail(error); diff --git a/e2e/paths/client-module/04_edit_pay_method.spec.js b/e2e/paths/client-module/04_edit_pay_method.spec.js index 11f61ea44..1d796e706 100644 --- a/e2e/paths/client-module/04_edit_pay_method.spec.js +++ b/e2e/paths/client-module/04_edit_pay_method.spec.js @@ -50,8 +50,10 @@ describe('Client', () => { return nightmare .waitToClick(selectors.clientPayMethod.payMethodInput) .waitToClick(selectors.clientPayMethod.payMethodIBANOption) + .waitForTextInInput(selectors.clientPayMethod.payMethodInput, 'PayMethod with IBAN') .clearInput(selectors.clientPayMethod.dueDayInput) .type(selectors.clientPayMethod.dueDayInput, '60') + .waitForTextInInput(selectors.clientPayMethod.dueDayInput, '60') .waitToClick(selectors.clientPayMethod.receivedCoreLCRCheckbox) .waitToClick(selectors.clientPayMethod.receivedCoreVNLCheckbox) .waitToClick(selectors.clientPayMethod.receivedB2BVNLCheckbox) @@ -66,6 +68,7 @@ describe('Client', () => { return nightmare .clearInput(selectors.clientPayMethod.IBANInput) .type(selectors.clientPayMethod.IBANInput, 'ES91 2100 0418 4502 0005 1332') + .waitForTextInInput(selectors.clientPayMethod.IBANInput, 'ES91 2100 0418 4502 0005 1332') .waitToClick(selectors.clientPayMethod.saveButton) .waitForSnackbar() .then(result => { diff --git a/gulpfile.js b/gulpfile.js index 659dee678..0c85a8935 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -71,6 +71,9 @@ gulp.task('services-only', async () => { * Runs the e2e tests, restoring the fixtures first. */ gulp.task('e2e', ['docker'], async () => { + if (argv.show || argv.s) + process.env.E2E_SHOW = true; + await runSequenceP('e2e-only'); }); diff --git a/services/client/common/models/client-credit.js b/services/client/common/models/client-credit.js deleted file mode 100644 index 98e2c5853..000000000 --- a/services/client/common/models/client-credit.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = Self => { - Self.installMethod('filter', filterParams); - - function filterParams(params) { - return { - where: { - clientFk: params.clientFk - }, - skip: (params.page - 1) * params.size, - limit: params.size, - order: params.order || 'created DESC', - include: { - relation: "worker", - scope: { - fields: ["id", "firstName", "name"] - } - } - }; - } -}; diff --git a/services/item/common/methods/item-barcode/crudItemBarcodes.js b/services/item/common/methods/item-barcode/crudItemBarcodes.js deleted file mode 100644 index 0b33736cd..000000000 --- a/services/item/common/methods/item-barcode/crudItemBarcodes.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = Self => { - Self.installCrudModel('crudItemBarcodes'); -}; diff --git a/services/item/common/methods/item-barcode/spec/crudItemBarcodes.spec.js b/services/item/common/methods/item-barcode/spec/crudItemBarcodes.spec.js deleted file mode 100644 index be3e52dd2..000000000 --- a/services/item/common/methods/item-barcode/spec/crudItemBarcodes.spec.js +++ /dev/null @@ -1,72 +0,0 @@ -// const crudItemBarcodes = require('../crudItemBarcodes'); -// const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; -// let mysql = require('mysql2'); - -// describe('Item crudItemBarcodes()', () => { -// let connection; -// beforeAll(() => { -// connection = mysql.createConnection({ -// multipleStatements: true, -// host: 'localhost', -// user: 'root', -// password: '', -// database: 'salix' -// }); -// }); - -// it('should call the destroyAll methodif there are ids in delete Array', done => { -// let self = jasmine.createSpyObj('self', ['remoteMethod', 'crudItemBarcodes', 'destroyAll', 'create', 'upsert']); - -// crudItemBarcodes(self); -// self.crudItemBarcodes({ -// delete: [1], -// create: [], -// update: [] -// }).then(result => { -// expect(self.destroyAll).toHaveBeenCalledWith({id: {inq: [1]}}); -// done(); -// }) -// .catch(catchErrors(done)); -// }); - -// it('should call the create method if there are ids in create Array', done => { -// let self = jasmine.createSpyObj('self', ['remoteMethod', 'crudItemBarcodes', 'destroyAll', 'create', 'upsert']); - -// crudItemBarcodes(self); -// self.crudItemBarcodes({ -// delete: [], -// create: [1], -// update: [] -// }).then(result => { -// expect(self.create).toHaveBeenCalledWith([1]); -// done(); -// }) -// .catch(catchErrors(done)); -// }); - -// it('should call the upsert method as many times as ids in update Array', done => { -// let self = jasmine.createSpyObj('self', ['remoteMethod', 'crudItemBarcodes', 'destroyAll', 'create', 'upsert']); - -// crudItemBarcodes(self); -// self.crudItemBarcodes({ -// delete: [], -// create: [], -// update: [1, 2] -// }).then(result => { -// expect(self.upsert).toHaveBeenCalledWith(1); -// expect(self.upsert).toHaveBeenCalledWith(2); -// expect(self.upsert.calls.count()).toEqual(2); -// done(); -// }) -// .catch(catchErrors(done)); -// }); - -// it('should return an error when attempting to save a duplicated barcode', done => { -// let callback = (err, res) => { -// expect(err.toString()).toBe("Error: Duplicate entry '4' for key 'PRIMARY'"); -// done(); -// }; - -// connection.query('INSERT INTO `vn`.`itemBarcode` VALUES (4, 2 ,4 );', callback); -// }); -// }); diff --git a/services/item/common/methods/item-niche/crudItemNiches.js b/services/item/common/methods/item-niche/crudItemNiches.js deleted file mode 100644 index c836ccfbf..000000000 --- a/services/item/common/methods/item-niche/crudItemNiches.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = Self => { - Self.installCrudModel('crudItemNiches'); -}; diff --git a/services/item/common/methods/item-niche/spec/crudItemNiches.spec.js b/services/item/common/methods/item-niche/spec/crudItemNiches.spec.js deleted file mode 100644 index a5ce94f70..000000000 --- a/services/item/common/methods/item-niche/spec/crudItemNiches.spec.js +++ /dev/null @@ -1,51 +0,0 @@ -// const crudItemNiches = require('../crudItemNiches'); -// const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; - -// describe('Item crudItemNiches()', () => { -// it('should call the destroyAll method if there are ids in delete Array', done => { -// let self = jasmine.createSpyObj('self', ['remoteMethod', 'crudItemNiches', 'destroyAll', 'create', 'upsert']); - -// crudItemNiches(self); -// self.crudItemNiches({ -// delete: [1], -// create: [], -// update: [] -// }).then(result => { -// expect(self.destroyAll).toHaveBeenCalledWith({id: {inq: [1]}}); -// done(); -// }) -// .catch(catchErrors(done)); -// }); - -// it('should call the create method if there are ids in create Array', done => { -// let self = jasmine.createSpyObj('self', ['remoteMethod', 'crudItemNiches', 'destroyAll', 'create', 'upsert']); - -// crudItemNiches(self); -// self.crudItemNiches({ -// delete: [], -// create: [1], -// update: [] -// }).then(result => { -// expect(self.create).toHaveBeenCalledWith([1]); -// done(); -// }) -// .catch(catchErrors(done)); -// }); - -// it('should call the upsert method as many times as ids in update Array', done => { -// let self = jasmine.createSpyObj('self', ['remoteMethod', 'crudItemNiches', 'destroyAll', 'create', 'upsert']); - -// crudItemNiches(self); -// self.crudItemNiches({ -// delete: [], -// create: [], -// update: [1, 2] -// }).then(result => { -// expect(self.upsert).toHaveBeenCalledWith(1); -// expect(self.upsert).toHaveBeenCalledWith(2); -// expect(self.upsert.calls.count()).toEqual(2); -// done(); -// }) -// .catch(catchErrors(done)); -// }); -// }); diff --git a/services/item/common/models/item-barcode.js b/services/item/common/models/item-barcode.js index be7898e66..094701113 100644 --- a/services/item/common/models/item-barcode.js +++ b/services/item/common/models/item-barcode.js @@ -1,6 +1,4 @@ module.exports = Self => { - require('../methods/item-barcode/crudItemBarcodes')(Self); - Self.validatesUniquenessOf('code', { message: `Barcode must be unique` }); diff --git a/services/loopback/common/methods/sale/filter.js b/services/loopback/common/methods/sale/filter.js deleted file mode 100644 index 5c1a322d0..000000000 --- a/services/loopback/common/methods/sale/filter.js +++ /dev/null @@ -1,39 +0,0 @@ -module.exports = Self => { - Self.installMethod('filter', filterParams); - - function filterParams(params) { - return { - where: { - ticketFk: params.ticketFk - }, - skip: (params.page - 1) * params.size, - limit: params.size, - order: params.order || 'concept ASC', - include: [{ - relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - }, - limit: 6 - } - }, - fields: ['itemFk', 'name'] - } - }, - { - relation: 'isChecked', - scope: { - fields: ['isChecked'] - } - }] - }; - } -}; diff --git a/services/loopback/common/methods/sale/saleComponentFilter.js b/services/loopback/common/methods/sale/saleComponentFilter.js deleted file mode 100644 index ea829cf24..000000000 --- a/services/loopback/common/methods/sale/saleComponentFilter.js +++ /dev/null @@ -1,51 +0,0 @@ -module.exports = Self => { - Self.installMethod('saleComponentFilter', filterParams); - - function filterParams(params) { - return { - where: { - ticketFk: params.ticketFk - }, - skip: (params.page - 1) * params.size, - limit: params.size, - order: params.order || 'concept ASC', - include: [{ - relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - }, - limit: 6 - } - }, - fields: ['itemFk', 'name'] - } - }, - { - relation: 'components', - scope: { - fields: ['componentFk', 'value'], - include: { - relation: 'componentRate', - scope: { - fields: ['componentTypeRate', 'name'], - include: { - relation: 'componentType', - scope: { - fields: ['type'] - } - } - } - } - } - }] - }; - } -}; diff --git a/services/loopback/common/models/sale.js b/services/loopback/common/models/sale.js index 7d7a0f869..129d14bb8 100644 --- a/services/loopback/common/models/sale.js +++ b/services/loopback/common/models/sale.js @@ -1,7 +1,5 @@ module.exports = Self => { - require('../methods/sale/filter')(Self); require('../methods/sale/getClaimableFromTicket')(Self); - require('../methods/sale/saleComponentFilter')(Self); require('../methods/sale/priceDifference')(Self); require('../methods/sale/moveToTicket')(Self); require('../methods/sale/reserve')(Self); diff --git a/services/ticket/common/methods/notes/crudTicketObservation.js b/services/ticket/common/methods/notes/crudTicketObservation.js deleted file mode 100644 index 04365eb12..000000000 --- a/services/ticket/common/methods/notes/crudTicketObservation.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = Self => { - Self.installCrudModel('crudTicketObservation'); -}; diff --git a/services/ticket/common/models/ticket-observation.js b/services/ticket/common/models/ticket-observation.js index d6b200aa2..50fc68331 100644 --- a/services/ticket/common/models/ticket-observation.js +++ b/services/ticket/common/models/ticket-observation.js @@ -1,6 +1,4 @@ module.exports = function(Self) { - require('../methods/notes/crudTicketObservation.js')(Self); - /* Self.validateAsync('observationTypeFk', validateObservationUniqueness, { message: `The observation type can't be repeated` });