From 1b3a8ddbdde53982a4231820ff3017d397d03a37 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 6 Mar 2024 12:03:35 +0100 Subject: [PATCH] refs #6755 fix restore --- modules/ticket/back/methods/ticket/restore.js | 16 ++++++++++------ modules/ticket/back/models/ticket-log.json | 2 +- modules/ticket/front/descriptor-menu/index.js | 15 ++++++++++----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index c85efb1c8e..754c2e5624 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -29,19 +29,23 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const ticket = await models.TicketLog.findById(id, { - fields: ['originFk', 'creationDate', 'newInstance'] + const ticket = await models.TicketLog.findOne({ + fields: ['originFk', 'creationDate', 'newInstance'], + where: { + originFk: id, + newInstance: {like: '%"isDeleted":true%'} + }, + order: 'creationDate DESC' }, myOptions); + console.log('id', id); console.log('ticket', ticket); const now = Date.vnNew(); const maxDate = new Date(ticket.creationDate); maxDate.setHours(maxDate.getHours() + 1); - if (ticket.newInstance.includes('isDeleted: true')) { - if (now > maxDate) - throw new UserError(`You can only restore a ticket within the first hour after deletion`); - } + if (now > maxDate) + throw new UserError(`You can only restore a ticket within the first hour after deletion`); // Send notification to salesPerson const salesPersonId = ticket.client().salesPersonFk; diff --git a/modules/ticket/back/models/ticket-log.json b/modules/ticket/back/models/ticket-log.json index ac912856b2..e46995a91c 100644 --- a/modules/ticket/back/models/ticket-log.json +++ b/modules/ticket/back/models/ticket-log.json @@ -25,7 +25,7 @@ "description": { "type": "string" }, - "changeModel": { + "changedModel": { "type": "string" }, "oldInstance": { diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index e719132677..a73fed500a 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -172,12 +172,17 @@ class Controller extends Section { } get canRestoreTicket() { - const isDeleted = this.ticket.isDeleted; - const now = Date.vnNew(); - const maxDate = new Date(this.ticket.updated); - maxDate.setHours(maxDate.getHours() + 1); + // const isDeleted = this.ticket.isDeleted; + // const now = Date.vnNew(); + // const maxDate = new Date(this.ticket.updated); + // maxDate.setHours(maxDate.getHours() + 1); - return isDeleted && (now <= maxDate); + // return isDeleted && (now <= maxDate); + return this.$http.get(`TicketLogs`).then(res => { + if (res && res.data.length) + console.log(res.data); + return true; + }); } restoreTicket() {