3888-ticket.expedition_moveExpedition #1097

Merged
vicent merged 26 commits from 3888-ticket.expedition_moveExpedition into dev 2022-11-02 13:54:11 +00:00
6 changed files with 130 additions and 23 deletions
Showing only changes of commit deb8a00dfb - Show all commits

View File

@ -0,0 +1,48 @@
module.exports = Self => {
Self.remoteMethod('deleteExpeditions', {
description: 'Delete the selected expeditions',
accessType: 'WRITE',
accepts: [{
arg: 'expeditionsIds',
type: ['number'],
required: true,
description: 'The expeditions ids to delete'
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/deleteExpeditions`,
verb: 'POST'
}
});
Self.deleteExpeditions = async(expeditionsIds, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const deletedExpeditions = await models.Expedition.destroyAll({
id: {inq: expeditionsIds}
}, myOptions);
if (tx) await tx.commit();
return deletedExpeditions;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -0,0 +1,59 @@
module.exports = Self => {
Self.remoteMethod('moveExpeditions', {
description: 'Move the selected expeditions to another ticket',
accessType: 'WRITE',
accepts: [{
arg: 'expeditionsIds',
type: ['number'],
required: true,
description: 'The expeditions ids to nove'
},
{
arg: 'ticketId',
type: 'number',
required: true,
description: 'the ticket id to which the expeditions are added'
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/moveExpeditions`,
verb: 'POST'
}
});
Self.moveExpeditions = async(expeditionsIds, ticketId, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const promises = [];
for (let expeditionsId of expeditionsIds) {
const expeditionToUpdate = await models.Expedition.findById(expeditionsId);
const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticketId, myOptions);
promises.push(expeditionUpdated);
}
const updated = await Promise.all(promises);
if (tx) await tx.commit();
return updated;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -1,3 +1,5 @@
module.exports = function(Self) {
require('../methods/expedition/filter')(Self);
require('../methods/expedition/deleteExpeditions')(Self);
require('../methods/expedition/moveExpeditions')(Self);
};

View File

@ -14,10 +14,10 @@
<vn-button icon="keyboard_arrow_down"
label="Move"
ng-click="moreOptions.show($event)"
ng-show="$ctrl.totalChecked">
disabled="!$ctrl.totalChecked">
</vn-button>
<vn-button
ng-show="$ctrl.checked.length > 0"
disabled="!$ctrl.checked.length"
ng-click="removeConfirm.show()"
icon="delete"
vn-tooltip="Delete expedition">

View File

@ -17,7 +17,7 @@ class Controller extends Section {
const checkedRows = [];
for (let row of rows) {
if (row.checked)
checkedRows.push(row);
checkedRows.push(row.id);
}
return checkedRows;
@ -27,18 +27,14 @@ class Controller extends Section {
return this.checked.length;
}
async onRemove() {
const params = [];
for (let expedition of this.checked)
params.push(expedition.id);
for (let id of params) {
await this.$http.delete(`Expeditions/${id}`)
.then(() => {
this.vnApp.showSuccess(this.$t('Expedition removed'));
this.$state.reload();
});
}
onRemove() {
const params = {expeditionsIds: this.checked};
const query = `Expeditions/deleteExpeditions`;
this.$http.post(query, params)
.then(() => {
this.vnApp.showSuccess(this.$t('Expedition removed'));
this.$state.reload();
});
}
createTicket(routeFk) {
@ -54,13 +50,12 @@ class Controller extends Section {
this.$http.post(query, ticketParams).then(res => {
if (routeFk) this.$http.patch(`Tickets/${res.data.id}`, {routeFk: routeFk});
const params = [];
for (let expedition of this.checked)
params.push(expedition.id);
const expeditionParams = {ticketFk: res.data.id};
for (let id of params)
this.$http.patch(`Expeditions/${id}`, expeditionParams);
const params = {
expeditionsIds: this.checked,
ticketId: res.data.id
};
const query = `Expeditions/moveExpeditions`;
this.$http.post(query, params);
this.vnApp.showSuccess(this.$t('Data saved!'));
this.$state.go('ticket.card.summary', {id: res.data.id});
});

View File

@ -1,2 +1,5 @@
Status log: Hitorial de estados
Expedition removed: Expedición eliminada
Expedition removed: Expedición eliminada
Move: Mover
New ticket without route: Nuevo ticket sin ruta
New ticket with route: Nuevo ticket con ruta