diff --git a/modules/ticket/back/methods/ticket/deleted.js b/modules/ticket/back/methods/ticket/delete.js similarity index 63% rename from modules/ticket/back/methods/ticket/deleted.js rename to modules/ticket/back/methods/ticket/delete.js index a7fa29a50..bca9e0428 100644 --- a/modules/ticket/back/methods/ticket/deleted.js +++ b/modules/ticket/back/methods/ticket/delete.js @@ -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}); }; }; diff --git a/modules/ticket/back/methods/ticket/specs/deleted.spec.js b/modules/ticket/back/methods/ticket/specs/delete.spec.js similarity index 92% rename from modules/ticket/back/methods/ticket/specs/deleted.spec.js rename to modules/ticket/back/methods/ticket/specs/delete.spec.js index 4127a56b7..1b017e989 100644 --- a/modules/ticket/back/methods/ticket/specs/deleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/delete.spec.js @@ -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; } diff --git a/modules/ticket/back/models/ticket.js b/modules/ticket/back/models/ticket.js index a5419c257..42ff1aeae 100644 --- a/modules/ticket/back/models/ticket.js +++ b/modules/ticket/back/models/ticket.js @@ -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); diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 709b0331e..53e300bfd 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -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')); }); diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index 96e87a4ce..05f91d34e 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -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();