refs #6755 fix restore

This commit is contained in:
Carlos Satorres 2024-03-06 12:03:35 +01:00
parent 70096e7a76
commit 1b3a8ddbdd
3 changed files with 21 additions and 12 deletions

View File

@ -29,19 +29,23 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const ticket = await models.TicketLog.findById(id, { const ticket = await models.TicketLog.findOne({
fields: ['originFk', 'creationDate', 'newInstance'] fields: ['originFk', 'creationDate', 'newInstance'],
where: {
originFk: id,
newInstance: {like: '%"isDeleted":true%'}
},
order: 'creationDate DESC'
}, myOptions); }, myOptions);
console.log('id', id);
console.log('ticket', ticket); console.log('ticket', ticket);
const now = Date.vnNew(); const now = Date.vnNew();
const maxDate = new Date(ticket.creationDate); const maxDate = new Date(ticket.creationDate);
maxDate.setHours(maxDate.getHours() + 1); maxDate.setHours(maxDate.getHours() + 1);
if (ticket.newInstance.includes('isDeleted: true')) { if (now > maxDate)
if (now > maxDate) throw new UserError(`You can only restore a ticket within the first hour after deletion`);
throw new UserError(`You can only restore a ticket within the first hour after deletion`);
}
// Send notification to salesPerson // Send notification to salesPerson
const salesPersonId = ticket.client().salesPersonFk; const salesPersonId = ticket.client().salesPersonFk;

View File

@ -25,7 +25,7 @@
"description": { "description": {
"type": "string" "type": "string"
}, },
"changeModel": { "changedModel": {
"type": "string" "type": "string"
}, },
"oldInstance": { "oldInstance": {

View File

@ -172,12 +172,17 @@ class Controller extends Section {
} }
get canRestoreTicket() { get canRestoreTicket() {
const isDeleted = this.ticket.isDeleted; // const isDeleted = this.ticket.isDeleted;
const now = Date.vnNew(); // const now = Date.vnNew();
const maxDate = new Date(this.ticket.updated); // const maxDate = new Date(this.ticket.updated);
maxDate.setHours(maxDate.getHours() + 1); // 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() { restoreTicket() {