From fe80a6b8c842c0d6a666c794ca4eedf9bb37235c Mon Sep 17 00:00:00 2001 From: gerard Date: Thu, 13 Sep 2018 12:36:52 +0200 Subject: [PATCH] Bug #651 Al borrar un ticket no se cambia su estado a eliminado --- services/loopback/common/methods/ticket/deleted.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/services/loopback/common/methods/ticket/deleted.js b/services/loopback/common/methods/ticket/deleted.js index 36bffaf95..2636963a8 100644 --- a/services/loopback/common/methods/ticket/deleted.js +++ b/services/loopback/common/methods/ticket/deleted.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('deleted', { + Self.remoteMethodCtx('deleted', { description: 'Sets the isDeleted value of a ticket to 1', accessType: '', accepts: [{ @@ -19,7 +19,15 @@ module.exports = Self => { } }); - Self.deleted = async params => { - return await Self.app.models.Ticket.update({id: params.id}, {isDeleted: '1'}); + Self.deleted = async(ctx, params) => { + await Self.app.models.Ticket.update({id: params.id}, {isDeleted: '1'}); + + 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}); }; };