2869-getSuggestedTickets_started_to_created #589
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
@ -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: [
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -104,9 +104,8 @@
|
|||
<tpl-body>
|
||||
<vn-horizontal>
|
||||
<vn-date-picker
|
||||
label="Starting date"
|
||||
ng-model="$ctrl.startedDate"
|
||||
required="true">
|
||||
label="Starting date"
|
||||
ng-model="$ctrl.createdDate">
|
||||
</vn-date-picker>
|
||||
</vn-horizontal>
|
||||
</tpl-body>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue