From 893320b1149fb33d73355b2895167b17cde5203c Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 4 Mar 2024 15:00:43 +0100 Subject: [PATCH 01/16] refs #6755 model ticketlog, restore --- modules/ticket/back/methods/ticket/restore.js | 5 +++ modules/ticket/back/models/ticket-log.json | 37 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index e268c3891..49e6c4389 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -37,6 +37,11 @@ module.exports = Self => { } }] }, myOptions); + const lastUpdatedTicket = await models.ticketLog.findById(id, { + include: [{ + + }] + }); const now = Date.vnNew(); const maxDate = new Date(ticket.updated); diff --git a/modules/ticket/back/models/ticket-log.json b/modules/ticket/back/models/ticket-log.json index d5d1e5520..ac912856b 100644 --- a/modules/ticket/back/models/ticket-log.json +++ b/modules/ticket/back/models/ticket-log.json @@ -5,5 +5,40 @@ "mysql": { "table": "ticketLog" } - } + }, + "properties": { + "id": { + "type": "string" + }, + "originFk": { + "type": "number" + }, + "userFk": { + "type":"number" + }, + "action": { + "type": "string" + }, + "creationDate": { + "type": "date" + }, + "description": { + "type": "string" + }, + "changeModel": { + "type": "string" + }, + "oldInstance": { + "type": "string" + }, + "newInstance": { + "type": "string" + }, + "changedModelId": { + "type": "number" + }, + "changedModelValue": { + "type": "string" + } + } } From cac388f986d28fd737c854bccc7a7eff4c5d86d9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 5 Mar 2024 09:43:07 +0100 Subject: [PATCH 02/16] refs #6755 fix ticket --- modules/ticket/back/methods/ticket/restore.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index 49e6c4389..8ba005b93 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -30,18 +30,8 @@ module.exports = Self => { Object.assign(myOptions, options); const ticket = await models.Ticket.findById(id, { - include: [{ - relation: 'client', - scope: { - fields: ['id', 'salesPersonFk'] - } - }] + fields: ['originFk', 'creationDate', 'newInstance'] }, myOptions); - const lastUpdatedTicket = await models.ticketLog.findById(id, { - include: [{ - - }] - }); const now = Date.vnNew(); const maxDate = new Date(ticket.updated); From 16fc446b852fb8b3903a28e25f3098f4679d4b2f Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 5 Mar 2024 10:46:15 +0100 Subject: [PATCH 03/16] refs #6755 fix method --- modules/ticket/back/methods/ticket/restore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index 8ba005b93..c92f8767e 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -29,7 +29,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const ticket = await models.Ticket.findById(id, { + const ticket = await models.TicketLog.findById(id, { fields: ['originFk', 'creationDate', 'newInstance'] }, myOptions); From 70096e7a762c6c928654ba98626a728e5dfe0b63 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 5 Mar 2024 14:24:32 +0100 Subject: [PATCH 04/16] refs #6755 fix restore --- modules/ticket/back/methods/ticket/restore.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index c92f8767e..c85efb1c8 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -33,12 +33,15 @@ module.exports = Self => { fields: ['originFk', 'creationDate', 'newInstance'] }, myOptions); + console.log('ticket', ticket); const now = Date.vnNew(); - const maxDate = new Date(ticket.updated); + const maxDate = new Date(ticket.creationDate); maxDate.setHours(maxDate.getHours() + 1); - if (now > maxDate) - throw new UserError(`You can only restore a ticket within the first hour after deletion`); + if (ticket.newInstance.includes('isDeleted: true')) { + 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; From 1b3a8ddbdde53982a4231820ff3017d397d03a37 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 6 Mar 2024 12:03:35 +0100 Subject: [PATCH 05/16] 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 c85efb1c8..754c2e562 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 ac912856b..e46995a91 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 e71913267..a73fed500 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() { From a14ab90d5a8ef1cb513c867ac50109c491fb68fb Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 6 Mar 2024 14:41:58 +0100 Subject: [PATCH 06/16] refs #6755 fix restore add fixtures --- db/dump/fixtures.before.sql | 7 +++++++ modules/ticket/front/descriptor-menu/index.js | 1 + 2 files changed, 8 insertions(+) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index aef0f13e3..b8f31ac3a 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3069,3 +3069,10 @@ INSERT INTO `vn`.`cmr` (id,truckPlate,observations,senderInstruccions,paymentIns UPDATE vn.department SET workerFk = null; + +INSERT INTO vn.ticketLog (originFk,userFk,`action`,creationDate,changedModel,newInstance,changedModelId,changedModelValue) + VALUES (9,9,'insert','2000-01-01 11:01:00.000','Ticket','{"isDeleted":true}',45,'Super Man'); + +UPDATE vn.ticket + SET isDeleted=1 + WHERE id=9; diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index a73fed500..245142a60 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -181,6 +181,7 @@ class Controller extends Section { return this.$http.get(`TicketLogs`).then(res => { if (res && res.data.length) console.log(res.data); + console.log(res); return true; }); } From 2e4a5029b8304f8a452b0033331c4313e7bc21c1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 6 Mar 2024 14:52:49 +0100 Subject: [PATCH 07/16] refs #6755 fix restore --- modules/ticket/back/methods/ticket/restore.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index 754c2e562..0d2452df9 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -38,6 +38,15 @@ module.exports = Self => { order: 'creationDate DESC' }, myOptions); + const ticketOG = await models.Ticket.findById(id, { + include: [{ + relation: 'client', + scope: { + fields: ['id', 'salesPersonFk'] + } + }] + }, myOptions); + console.log('id', id); console.log('ticket', ticket); const now = Date.vnNew(); @@ -48,7 +57,7 @@ module.exports = Self => { throw new UserError(`You can only restore a ticket within the first hour after deletion`); // Send notification to salesPerson - const salesPersonId = ticket.client().salesPersonFk; + const salesPersonId = ticketOG.client().salesPersonFk; if (salesPersonId) { const url = await Self.app.models.Url.getUrl(); const message = $t(`I have restored the ticket id`, { @@ -59,12 +68,12 @@ module.exports = Self => { } const fullYear = Date.vnNew().getFullYear(); - const newShipped = ticket.shipped; - const newLanded = ticket.landed; + const newShipped = ticketOG.shipped; + const newLanded = ticketOG.landed; newShipped.setFullYear(fullYear); newLanded.setFullYear(fullYear); - return ticket.updateAttributes({ + return ticketOG.updateAttributes({ shipped: newShipped, landed: newLanded, isDeleted: false From d4d3fdceb5075874f19d4a163d0bc54326c6e130 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 7 Mar 2024 11:36:30 +0100 Subject: [PATCH 08/16] refs #6755 fix canRestoreTicket --- modules/ticket/back/methods/ticket/restore.js | 2 -- .../back/methods/ticket/specs/filter.spec.js | 2 +- .../back/methods/ticket/specs/restore.spec.js | 18 ++++++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index 0d2452df9..9dde43ff9 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -47,8 +47,6 @@ module.exports = Self => { }] }, myOptions); - console.log('id', id); - console.log('ticket', ticket); const now = Date.vnNew(); const maxDate = new Date(ticket.creationDate); maxDate.setHours(maxDate.getHours() + 1); diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index c1d3f1a9c..09c4ebbb7 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -68,7 +68,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(5); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/specs/restore.spec.js b/modules/ticket/back/methods/ticket/specs/restore.spec.js index 3b35ae2b4..736e68628 100644 --- a/modules/ticket/back/methods/ticket/specs/restore.spec.js +++ b/modules/ticket/back/methods/ticket/specs/restore.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); const models = app.models; -describe('ticket restore()', () => { +fdescribe('ticket restore()', () => { const employeeUser = 1110; - const ticketId = 18; + const ticketId = 9; const activeCtx = { accessToken: {userId: employeeUser}, headers: { @@ -48,25 +48,31 @@ describe('ticket restore()', () => { const tx = await app.models.Ticket.beginTransaction({}); const now = Date.vnNew(); + console.log('now', now); try { const options = {transaction: tx}; - const ticketBeforeUpdate = await models.Ticket.findById(ticketId, null, options); + const ticketBeforeUpdate = await models.TicketLog.findById(ticketId, null, options); await ticketBeforeUpdate.updateAttributes({ - isDeleted: true, - updated: now + creationDate: '2001-01-01T11:00:00.000Z', }, options); - const ticketAfterUpdate = await models.Ticket.findById(ticketId, null, options); + console.log('ticketBeforeUpdate', ticketBeforeUpdate); + const ticketAfterUpdate = await models.TicketLog.findById(ticketId, null, options); + console.log('ticketAfterUpdate: ', ticketAfterUpdate); expect(ticketAfterUpdate.isDeleted).toBeTruthy(); await models.Ticket.restore(ctx, ticketId, options); const ticketAfterRestore = await models.Ticket.findById(ticketId, null, options); + console.log('ticketAfterRestore: ', ticketAfterRestore); const fullYear = now.getFullYear(); + console.log('fullYear: ', fullYear); const shippedFullYear = ticketAfterRestore.shipped.getFullYear(); + console.log('shippedFullYear: ', shippedFullYear); const landedFullYear = ticketAfterRestore.landed.getFullYear(); + console.log('landedFullYear: ', landedFullYear); expect(ticketAfterRestore.isDeleted).toBeFalsy(); expect(shippedFullYear).toEqual(fullYear); From 8a16c24245afac127bbf785ff9923ed8f6ebaf88 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 8 Mar 2024 12:27:47 +0100 Subject: [PATCH 09/16] refs #6755 fix ticket --- modules/ticket/front/descriptor-menu/index.js | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 245142a60..f60e0012c 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -8,6 +8,7 @@ class Controller extends Section { this.vnReport = vnReport; this.vnEmail = vnEmail; this.vnFile = vnFile; + this.restoreTicket = vnRestoreTicket; } get ticketId() { @@ -172,18 +173,18 @@ 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 this.$http.get(`TicketLogs`).then(res => { - if (res && res.data.length) - console.log(res.data); - console.log(res); - return true; - }); + return isDeleted && (now <= maxDate); + // return this.$http.get(`TicketLogs`).then(res => { + // if (res && res.data.length) + // console.log(res.data); + // console.log(res); + // return true; + // }); } restoreTicket() { From 879adfaac8db6a72e92bf607004e5f0c207d081e Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 8 Mar 2024 14:59:33 +0100 Subject: [PATCH 10/16] refs #6755 restore fix --- .../ticket/front/descriptor-menu/index.html | 1 + modules/ticket/front/descriptor-menu/index.js | 45 ++++++++++++------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index cb7eeb8ee..0b9b1b2a1 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -86,6 +86,7 @@ translate> Delete ticket + {{$ctrl.canRestoreTicket}} { + console.log(res); + console.log(res.data.creationDate); + if (res && res.data) { + console.log(res.data); + const now = Date.vnNew(); + const maxDate = new Date(res.data.creationDate); + maxDate.setHours(maxDate.getHours() + 1); + console.log(now, maxDatenow); + console.log(now.getTime(), maxDate.getTime()); + if (now <= maxDate) + return this.canRestoreTicket = true; + } + this.canRestoreTicket = false; + }) + .catch(() => { + console.log('ENTRY'); + this.canRestoreTicket = false; + }); } get isInvoiced() { @@ -172,21 +200,6 @@ 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); - - return isDeleted && (now <= maxDate); - // return this.$http.get(`TicketLogs`).then(res => { - // if (res && res.data.length) - // console.log(res.data); - // console.log(res); - // return true; - // }); - } - restoreTicket() { return this.$http.post(`Tickets/${this.id}/restore`) .then(() => this.reload()) From ed572126181361995176c6d148096a9d595d2eae Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 12 Mar 2024 12:55:14 +0100 Subject: [PATCH 11/16] refs #6755 fix restore --- modules/ticket/back/methods/ticket/restore.js | 16 +++++------ .../back/methods/ticket/specs/restore.spec.js | 27 +++++++++++-------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index 9dde43ff9..555982f8d 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -29,7 +29,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const ticket = await models.TicketLog.findOne({ + const ticketLog = await models.TicketLog.findOne({ fields: ['originFk', 'creationDate', 'newInstance'], where: { originFk: id, @@ -38,7 +38,7 @@ module.exports = Self => { order: 'creationDate DESC' }, myOptions); - const ticketOG = await models.Ticket.findById(id, { + const ticket = await models.Ticket.findById(id, { include: [{ relation: 'client', scope: { @@ -48,14 +48,14 @@ module.exports = Self => { }, myOptions); const now = Date.vnNew(); - const maxDate = new Date(ticket.creationDate); + const maxDate = new Date(ticketLog.creationDate); maxDate.setHours(maxDate.getHours() + 1); - if (now > maxDate) + throw new UserError(`You can only restore a ticket within the first hour after deletion`); // Send notification to salesPerson - const salesPersonId = ticketOG.client().salesPersonFk; + const salesPersonId = ticket.client().salesPersonFk; if (salesPersonId) { const url = await Self.app.models.Url.getUrl(); const message = $t(`I have restored the ticket id`, { @@ -66,12 +66,12 @@ module.exports = Self => { } const fullYear = Date.vnNew().getFullYear(); - const newShipped = ticketOG.shipped; - const newLanded = ticketOG.landed; + const newShipped = ticket.shipped; + const newLanded = ticket.landed; newShipped.setFullYear(fullYear); newLanded.setFullYear(fullYear); - return ticketOG.updateAttributes({ + return ticket.updateAttributes({ shipped: newShipped, landed: newLanded, isDeleted: false diff --git a/modules/ticket/back/methods/ticket/specs/restore.spec.js b/modules/ticket/back/methods/ticket/specs/restore.spec.js index 736e68628..a44d39a7b 100644 --- a/modules/ticket/back/methods/ticket/specs/restore.spec.js +++ b/modules/ticket/back/methods/ticket/specs/restore.spec.js @@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); const models = app.models; -fdescribe('ticket restore()', () => { +describe('ticket restore()', () => { const employeeUser = 1110; const ticketId = 9; const activeCtx = { @@ -48,31 +48,36 @@ fdescribe('ticket restore()', () => { const tx = await app.models.Ticket.beginTransaction({}); const now = Date.vnNew(); - console.log('now', now); try { const options = {transaction: tx}; - const ticketBeforeUpdate = await models.TicketLog.findById(ticketId, null, options); + const ticketBeforeUpdate = await models.Ticket.findById(ticketId, null, options); await ticketBeforeUpdate.updateAttributes({ - creationDate: '2001-01-01T11:00:00.000Z', + isDeleted: true, + updated: now }, options); - console.log('ticketBeforeUpdate', ticketBeforeUpdate); - const ticketAfterUpdate = await models.TicketLog.findById(ticketId, null, options); - console.log('ticketAfterUpdate: ', ticketAfterUpdate); + await models.TicketLog.create({ + originFk: ticketId, + userFk: employeeUser, + action: 'update', + changedModel: 'Ticket', + creationDate: new Date('2001-01-01 11:01:00'), + newInstance: '{"isDeleted":true}' + }, options); + + const ticketAfterUpdate = await models.Ticket.findById(ticketId, null, options); expect(ticketAfterUpdate.isDeleted).toBeTruthy(); await models.Ticket.restore(ctx, ticketId, options); const ticketAfterRestore = await models.Ticket.findById(ticketId, null, options); - console.log('ticketAfterRestore: ', ticketAfterRestore); const fullYear = now.getFullYear(); - console.log('fullYear: ', fullYear); + const shippedFullYear = ticketAfterRestore.shipped.getFullYear(); - console.log('shippedFullYear: ', shippedFullYear); + const landedFullYear = ticketAfterRestore.landed.getFullYear(); - console.log('landedFullYear: ', landedFullYear); expect(ticketAfterRestore.isDeleted).toBeFalsy(); expect(shippedFullYear).toEqual(fullYear); From a6d1c5b6db243a1c032f693da5e9180fefe44bbd Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 12 Mar 2024 13:33:14 +0100 Subject: [PATCH 12/16] refs #6755 remove --- modules/ticket/front/descriptor-menu/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index 0b9b1b2a1..cb7eeb8ee 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -86,7 +86,6 @@ translate> Delete ticket - {{$ctrl.canRestoreTicket}} Date: Wed, 13 Mar 2024 11:46:43 +0100 Subject: [PATCH 13/16] refs #6755 remove console --- modules/ticket/front/descriptor-menu/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 9c7a58719..d2dd13f73 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -46,22 +46,16 @@ class Controller extends Section { }; this.$http.get(`TicketLogs/findOne`, {filter}) .then(res => { - console.log(res); - console.log(res.data.creationDate); if (res && res.data) { - console.log(res.data); const now = Date.vnNew(); const maxDate = new Date(res.data.creationDate); maxDate.setHours(maxDate.getHours() + 1); - console.log(now, maxDatenow); - console.log(now.getTime(), maxDate.getTime()); if (now <= maxDate) return this.canRestoreTicket = true; } this.canRestoreTicket = false; }) .catch(() => { - console.log('ENTRY'); this.canRestoreTicket = false; }); } From 1315bfda8839d89c68ebafc117341d5499d576f0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Mar 2024 14:18:53 +0100 Subject: [PATCH 14/16] refs #6755 fix test --- db/dump/fixtures.before.sql | 8 -------- .../back/methods/ticket-log/specs/getChanges.spec.js | 4 ++-- modules/ticket/back/methods/ticket/restore.js | 5 ++--- .../ticket/back/methods/ticket/specs/filter.spec.js | 2 +- .../ticket/back/methods/ticket/specs/restore.spec.js | 12 ++++++++++++ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 1f6c44d2e..35de9dd47 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3068,14 +3068,6 @@ INSERT INTO `vn`.`cmr` (id,truckPlate,observations,senderInstruccions,paymentIns UPDATE vn.department SET workerFk = null; -INSERT INTO vn.ticketLog (originFk,userFk,`action`,creationDate,changedModel,newInstance,changedModelId,changedModelValue) - VALUES (9,9,'insert','2000-01-01 11:01:00.000','Ticket','{"isDeleted":true}',45,'Super Man'); - -UPDATE vn.ticket - SET isDeleted=1 - WHERE id=9; --- NEW WAREHOUSE - INSERT INTO vn.packaging VALUES('--', 2745600.00, 100.00, 120.00, 220.00, 0.00, 1, '2001-01-01 00:00:00.000', NULL, NULL, NULL, 0.00, 16, 0.00, 0, NULL, 0.00, NULL, NULL, 0, NULL, 0, 0); diff --git a/modules/ticket/back/methods/ticket-log/specs/getChanges.spec.js b/modules/ticket/back/methods/ticket-log/specs/getChanges.spec.js index 04f42f7be..cccaa182f 100644 --- a/modules/ticket/back/methods/ticket-log/specs/getChanges.spec.js +++ b/modules/ticket/back/methods/ticket-log/specs/getChanges.spec.js @@ -9,8 +9,8 @@ describe('ticketLog getChanges()', () => { it('should return the changes in the sales of a ticket', async() => { const ticketId = 16; - const changues = await models.TicketLog.getChanges(ctx, ticketId); + const changes = await models.TicketLog.getChanges(ctx, ticketId); - expect(changues).toContain(`Change quantity`); + expect(changes).toContain(`Change quantity`); }); }); diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index 555982f8d..01b5d1652 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -48,10 +48,9 @@ module.exports = Self => { }, myOptions); const now = Date.vnNew(); - const maxDate = new Date(ticketLog.creationDate); + const maxDate = new Date(ticketLog?.creationDate); maxDate.setHours(maxDate.getHours() + 1); - if (now > maxDate) - + if (!ticketLog || now > maxDate) throw new UserError(`You can only restore a ticket within the first hour after deletion`); // Send notification to salesPerson diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 09c4ebbb7..c1d3f1a9c 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -68,7 +68,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(5); + expect(result.length).toEqual(6); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/specs/restore.spec.js b/modules/ticket/back/methods/ticket/specs/restore.spec.js index a44d39a7b..121a6ba96 100644 --- a/modules/ticket/back/methods/ticket/specs/restore.spec.js +++ b/modules/ticket/back/methods/ticket/specs/restore.spec.js @@ -30,10 +30,21 @@ describe('ticket restore()', () => { try { const options = {transaction: tx}; const ticket = await models.Ticket.findById(ticketId, null, options); + await ticket.updateAttributes({ isDeleted: true, updated: now }, options); + + await models.TicketLog.create({ + originFk: ticketId, + userFk: employeeUser, + action: 'update', + changedModel: 'Ticket', + creationDate: new Date('2001-01-01 10:59:00'), + newInstance: '{"isDeleted":true}' + }, options); + await app.models.Ticket.restore(ctx, ticketId, options); await tx.rollback(); } catch (e) { @@ -52,6 +63,7 @@ describe('ticket restore()', () => { const options = {transaction: tx}; const ticketBeforeUpdate = await models.Ticket.findById(ticketId, null, options); + await ticketBeforeUpdate.updateAttributes({ isDeleted: true, updated: now From 33bd21d40b00f7658d7c266ffc555b599e1bfab0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Mar 2024 16:29:05 +0100 Subject: [PATCH 15/16] refs #6755 fix model --- modules/ticket/back/models/ticket-log.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/models/ticket-log.json b/modules/ticket/back/models/ticket-log.json index e46995a91..32b4afd13 100644 --- a/modules/ticket/back/models/ticket-log.json +++ b/modules/ticket/back/models/ticket-log.json @@ -29,13 +29,13 @@ "type": "string" }, "oldInstance": { - "type": "string" + "type": "any" }, "newInstance": { - "type": "string" + "type": "any" }, "changedModelId": { - "type": "number" + "type": "string" }, "changedModelValue": { "type": "string" From dd7c70013055f9bb199a867a9c629920ff9000de Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 14 Mar 2024 09:53:50 +0100 Subject: [PATCH 16/16] refs #6755 fix test --- db/dump/fixtures.before.sql | 3 ++ .../front/descriptor-menu/index.spec.js | 37 ------------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 35de9dd47..8ea0baff2 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3731,3 +3731,6 @@ INSERT INTO vn.report (name) VALUES ('LabelCollection'); INSERT INTO vn.parkingLog(originFk, userFk, `action`, creationDate, description, changedModel,oldInstance, newInstance, changedModelId, changedModelValue) VALUES(1, 18, 'update', util.VN_CURDATE(), NULL, 'SaleGroup', '{"parkingFk":null}', '{"parkingFk":1}', 1, NULL); + +INSERT INTO vn.ticketLog (originFk,userFk,`action`,creationDate,changedModel,newInstance,changedModelId,changedModelValue) + VALUES (18,9,'insert','2001-01-01 11:01:00.000','Ticket','{"isDeleted":true}',45,'Super Man'); diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index 6d74881b8..80ad9a33a 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -40,29 +40,6 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { controller.ticket = ticket; })); - describe('canRestoreTicket() getter', () => { - it('should return true for a ticket deleted within the last hour', () => { - controller.ticket.isDeleted = true; - controller.ticket.updated = Date.vnNew(); - - const result = controller.canRestoreTicket; - - expect(result).toBeTruthy(); - }); - - it('should return false for a ticket deleted more than one hour ago', () => { - const pastHour = Date.vnNew(); - pastHour.setHours(pastHour.getHours() - 2); - - controller.ticket.isDeleted = true; - controller.ticket.updated = pastHour; - - const result = controller.canRestoreTicket; - - expect(result).toBeFalsy(); - }); - }); - describe('addTurn()', () => { it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => { controller.$.addTurn = {hide: () => {}}; @@ -105,20 +82,6 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { }); }); - describe('restoreTicket()', () => { - it('should make a query to restore the ticket and call vnApp.showSuccess()', () => { - jest.spyOn(controller, 'reload').mockReturnThis(); - jest.spyOn(controller.vnApp, 'showSuccess'); - - $httpBackend.expectPOST(`Tickets/${ticket.id}/restore`).respond(); - controller.restoreTicket(); - $httpBackend.flush(); - - expect(controller.reload).toHaveBeenCalled(); - expect(controller.vnApp.showSuccess).toHaveBeenCalled(); - }); - }); - describe('showPdfDeliveryNote()', () => { it('should open a new window showing a delivery note PDF document', () => { jest.spyOn(window, 'open').mockReturnThis();