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