This commit is contained in:
parent
6e2c71eca9
commit
c49f72b36c
|
@ -1,7 +1,7 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('deleted', {
|
Self.remoteMethodCtx('delete', {
|
||||||
description: 'Sets the isDeleted value of a ticket to 1',
|
description: 'Sets the isDeleted value of a ticket to 1',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
|
@ -16,25 +16,25 @@ module.exports = Self => {
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/deleted`,
|
path: `/delete`,
|
||||||
verb: 'post'
|
verb: 'post'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.deleted = async(ctx, params) => {
|
Self.delete = async(ctx, params) => {
|
||||||
let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}});
|
let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}});
|
||||||
if (claimOfATicket)
|
if (claimOfATicket)
|
||||||
throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id);
|
throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id);
|
||||||
|
|
||||||
let currentTicket = await Self.app.models.Ticket.findById(params.id);
|
let currentTicket = await Self.app.models.Ticket.findById(params.id);
|
||||||
await currentTicket.updateAttributes({isDeleted: '1'});
|
await currentTicket.updateAttributes({isDeleted: true});
|
||||||
|
|
||||||
if (ctx.req.accessToken) {
|
let userId = ctx.req.accessToken.userId;
|
||||||
let token = ctx.req.accessToken;
|
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}});
|
||||||
let currentUserId = token && token.userId;
|
params.workerFk = worker.id;
|
||||||
let worker = await Self.app.models.Worker.findOne({where: {userFk: currentUserId}});
|
let state = await Self.app.models.State.findOne({where: {code: 'ERASED'}});
|
||||||
params.workerFk = worker.id;
|
|
||||||
}
|
|
||||||
return await Self.app.models.TicketTracking.create({ticketFk: params.id, stateFk: 17, workerFk: params.workerFk});
|
return await Self.app.models.TicketTracking.create({ticketFk: params.id, stateFk: state.id, workerFk: params.workerFk});
|
||||||
};
|
};
|
||||||
};
|
};
|
|
@ -24,7 +24,7 @@ describe('ticket deleted()', () => {
|
||||||
it('should set a ticket to deleted and log the change on TicketState table', async() => {
|
it('should set a ticket to deleted and log the change on TicketState table', async() => {
|
||||||
let ctx = {req: {accessToken: {userId: 9}}};
|
let ctx = {req: {accessToken: {userId: 9}}};
|
||||||
let params = {id: ticket.id};
|
let params = {id: ticket.id};
|
||||||
await app.models.Ticket.deleted(ctx, params);
|
await app.models.Ticket.delete(ctx, params);
|
||||||
|
|
||||||
let deletedTicket = await app.models.Ticket.findOne({where: {id: ticket.id}, fields: ['isDeleted']});
|
let deletedTicket = await app.models.Ticket.findOne({where: {id: ticket.id}, fields: ['isDeleted']});
|
||||||
let changedState = await app.models.TicketState.findOne({where: {ticketFk: ticket.id}});
|
let changedState = await app.models.TicketState.findOne({where: {ticketFk: ticket.id}});
|
||||||
|
@ -39,7 +39,7 @@ describe('ticket deleted()', () => {
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await app.models.Ticket.deleted(ctx, params);
|
await app.models.Ticket.delete(ctx, params);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
|
@ -10,7 +10,7 @@ module.exports = Self => {
|
||||||
require('../methods/ticket/new')(Self);
|
require('../methods/ticket/new')(Self);
|
||||||
require('../methods/ticket/isEditable')(Self);
|
require('../methods/ticket/isEditable')(Self);
|
||||||
require('../methods/ticket/threeLastActive')(Self);
|
require('../methods/ticket/threeLastActive')(Self);
|
||||||
require('../methods/ticket/deleted')(Self);
|
require('../methods/ticket/delete')(Self);
|
||||||
require('../methods/ticket/getVAT')(Self);
|
require('../methods/ticket/getVAT')(Self);
|
||||||
require('../methods/ticket/getSales')(Self);
|
require('../methods/ticket/getSales')(Self);
|
||||||
require('../methods/ticket/getSalesPersonMana')(Self);
|
require('../methods/ticket/getSalesPersonMana')(Self);
|
||||||
|
|
|
@ -127,7 +127,7 @@ class Controller {
|
||||||
deleteTicket(response) {
|
deleteTicket(response) {
|
||||||
if (response === 'ACCEPT') {
|
if (response === 'ACCEPT') {
|
||||||
let params = {id: this.ticket.id};
|
let params = {id: this.ticket.id};
|
||||||
this.$http.post(`/ticket/api/Tickets/deleted`, params).then(() => {
|
this.$http.post(`/ticket/api/Tickets/delete`, params).then(() => {
|
||||||
this.$state.go('ticket.index');
|
this.$state.go('ticket.index');
|
||||||
this.vnApp.showSuccess(this.$translate.instant('Ticket deleted'));
|
this.vnApp.showSuccess(this.$translate.instant('Ticket deleted'));
|
||||||
});
|
});
|
||||||
|
|
|
@ -62,7 +62,7 @@ describe('Ticket Component vnTicketDescriptor', () => {
|
||||||
spyOn(controller.$state, 'go');
|
spyOn(controller.$state, 'go');
|
||||||
spyOn(controller.vnApp, 'showSuccess');
|
spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
||||||
$httpBackend.expectPOST(`/ticket/api/Tickets/deleted`, {id: 2}).respond();
|
$httpBackend.expectPOST(`/ticket/api/Tickets/delete`, {id: 2}).respond();
|
||||||
controller.deleteTicket('ACCEPT');
|
controller.deleteTicket('ACCEPT');
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue