diff --git a/modules/route/back/methods/route/clone.js b/modules/route/back/methods/route/clone.js index ece232ccf..d56118e08 100644 --- a/modules/route/back/methods/route/clone.js +++ b/modules/route/back/methods/route/clone.js @@ -10,10 +10,10 @@ module.exports = Self => { description: 'The routes ids to clone' }, { - arg: 'started', + arg: 'created', type: 'date', required: true, - description: 'The started date for all routes' + description: 'The created date for all routes' } ], returns: { @@ -26,7 +26,7 @@ module.exports = Self => { } }); - Self.clone = async(ids, started) => { + Self.clone = async(ids, created) => { const tx = await Self.beginTransaction({}); try { const options = {transaction: tx}; @@ -39,8 +39,7 @@ module.exports = Self => { throw new Error(`The amount of routes found don't match`); const routes = originalRoutes.map(route => { - route.started = started; - route.created = new Date(); + route.created = created; return route; }); diff --git a/modules/route/back/methods/route/getSuggestedTickets.js b/modules/route/back/methods/route/getSuggestedTickets.js index d988555f3..12bde1684 100644 --- a/modules/route/back/methods/route/getSuggestedTickets.js +++ b/modules/route/back/methods/route/getSuggestedTickets.js @@ -38,10 +38,10 @@ module.exports = Self => { for (let zoneAgencyMode of zoneAgencyModes) zoneIds.push(zoneAgencyMode.zoneFk); - const minDate = new Date(route.finished); + const minDate = new Date(route.created); minDate.setHours(0, 0, 0, 0); - const maxDate = new Date(route.finished); + const maxDate = new Date(route.created); maxDate.setHours(23, 59, 59, 59); let tickets = await Self.app.models.Ticket.find({ @@ -49,7 +49,7 @@ module.exports = Self => { agencyModeFk: route.agencyModeFk, zoneFk: {inq: zoneIds}, id: {nin: idsToExclude}, - landed: {between: [minDate, maxDate]} + created: {between: [minDate, maxDate]} }, include: [ { diff --git a/modules/route/back/methods/route/specs/clone.spec.js b/modules/route/back/methods/route/specs/clone.spec.js index c0f5f04f1..d1fc6b297 100644 --- a/modules/route/back/methods/route/specs/clone.spec.js +++ b/modules/route/back/methods/route/specs/clone.spec.js @@ -1,14 +1,14 @@ const app = require('vn-loopback/server/server'); describe('route clone()', () => { - const startDate = new Date(); + const createdDate = new Date(); it('should throw an error if the amount of ids pased to the clone function do no match the database', async() => { const ids = [996, 997, 998, 999]; let error; try { - await app.models.Route.clone(ids, startDate); + await app.models.Route.clone(ids, createdDate); } catch (e) { error = e; } @@ -20,7 +20,7 @@ describe('route clone()', () => { it('should clone two routes', async() => { const ids = [1, 2]; - const clones = await app.models.Route.clone(ids, startDate); + const clones = await app.models.Route.clone(ids, createdDate); expect(clones.length).toEqual(2); diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html index 6331537f8..5a503b149 100644 --- a/modules/route/front/index/index.html +++ b/modules/route/front/index/index.html @@ -104,9 +104,8 @@ + label="Starting date" + ng-model="$ctrl.createdDate"> diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js index 2dc767f4c..b94acb55a 100644 --- a/modules/route/front/index/index.js +++ b/modules/route/front/index/index.js @@ -41,19 +41,26 @@ export default class Controller extends Section { } openClonationDialog() { - this.startedDate = new Date(); this.$.clonationDialog.show(); + this.createdDate = new Date(); } cloneSelectedRoutes() { - const routesIds = []; - for (let route of this.checked) - routesIds.push(route.id); + try { + if (!this.createdDate) + throw new Error(`The date can't be empty`); - return this.$http.post('Routes/clone', {ids: routesIds, started: this.startedDate}).then(() => { - this.$.model.refresh(); - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + const routesIds = []; + for (let route of this.checked) + routesIds.push(route.id); + + return this.$http.post('Routes/clone', {ids: routesIds, created: this.createdDate}).then(() => { + this.$.model.refresh(); + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } catch (e) { + this.vnApp.showError(this.$t(e.message)); + } } onDrop($event) { diff --git a/modules/route/front/index/index.spec.js b/modules/route/front/index/index.spec.js index 8346f924c..8143f1157 100644 --- a/modules/route/front/index/index.spec.js +++ b/modules/route/front/index/index.spec.js @@ -62,7 +62,7 @@ describe('Component vnRouteIndex', () => { describe('cloneSelectedRoutes()', () => { it('should perform an http request to Routes/clone', () => { - controller.startedDate = new Date(); + controller.createdDate = new Date(); $httpBackend.expect('POST', 'Routes/clone').respond(); controller.cloneSelectedRoutes(); diff --git a/modules/route/front/index/locale/es.yml b/modules/route/front/index/locale/es.yml index 40cd5f2b5..591ea80d8 100644 --- a/modules/route/front/index/locale/es.yml +++ b/modules/route/front/index/locale/es.yml @@ -1,5 +1,5 @@ Vehicle: Vehículo Download selected routes as PDF: Descargar rutas seleccionadas como PDF Clone selected routes: Clonar rutas seleccionadas -Select the starting date: Seleccione fecha de inicio +The date can't be empty: La fecha no puede estar vacía Starting date: Fecha de inicio \ No newline at end of file