#1202 refactor del cambio de estado de un ticket
gitea/salix/dev This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2019-03-05 12:01:53 +01:00
parent 596eb8d695
commit d37d314304
2 changed files with 28 additions and 24 deletions

View File

@ -23,23 +23,28 @@ module.exports = Self => {
}
});
Self.changeState = async(ctx, data) => {
Self.changeState = async(ctx, params) => {
let userId = ctx.req.accessToken.userId;
let $ = Self.app.models;
if (!data.stateFk)
if (!params.stateFk && !params.code)
throw new UserError('State cannot be blank');
if (params.code) {
let state = await $.State.findOne({where: {code: params.code}, fields: ['id']});
params.stateFk = state.id;
}
let isProduction = await $.Account.hasRole(userId, 'production');
let isSalesPerson = await $.Account.hasRole(userId, 'salesPerson');
let ticket = await $.TicketState.findById(
data.ticketFk,
params.ticketFk,
{fields: ['stateFk']}
);
let oldState = await $.State.findById(ticket.stateFk);
let newState = await $.State.findById(data.stateFk);
let newState = await $.State.findById(params.stateFk);
let isAllowed = isProduction || isSalesPerson
&& oldState.isEditable()
@ -50,9 +55,9 @@ module.exports = Self => {
if (newState.code != 'PICKER_DESIGNED') {
let worker = await $.Worker.findOne({where: {userFk: userId}});
data.workerFk = worker.id;
params.workerFk = worker.id;
}
return await $.TicketTracking.create(data);
return await $.TicketTracking.create(params);
};
};

View File

@ -17,12 +17,7 @@ class Controller {
set ticket(value) {
this._ticket = value;
if (!value) return;
this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/summary`).then(res => {
if (res && res.data)
this.summary = res.data;
});
if (value) this.getSummary();
}
get formattedAddress() {
@ -34,6 +29,13 @@ class Controller {
return `${address.street} - ${address.city} ${province}`;
}
getSummary() {
this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/summary`).then(res => {
if (res && res.data)
this.summary = res.data;
});
}
showDescriptor(event, itemFk) {
this.quicklinks = {
btnThree: {
@ -64,25 +66,22 @@ class Controller {
}
setOkState() {
let filter = {where: {code: 'OK'}, fields: ['id']};
let json = encodeURIComponent(JSON.stringify(filter));
this.$http.get(`/ticket/api/States?filter=${json}`).then(res => {
this.changeTicketState(res.data[0].id);
});
}
changeTicketState(value) {
let params;
let params = {};
if (this.$state.params.id)
params = {ticketFk: this.$state.params.id, stateFk: value};
params = {ticketFk: this.$state.params.id};
if (!this.$state.params.id)
params = {ticketFk: this.ticket.id, stateFk: value};
params = {ticketFk: this.ticket.id};
params.code = 'OK';
this.$http.post(`/ticket/api/TicketTrackings/changeState`, params).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
if (this.card) this.card.reload();
if (this.card)
this.card.reload();
else
this.getSummary();
});
}
}