6755-restoreRefactor #2158

Merged
carlossa merged 20 commits from 6755-restoreRefactor into dev 2024-03-14 08:56:10 +00:00
3 changed files with 21 additions and 12 deletions
Showing only changes of commit 1b3a8ddbdd - Show all commits

View File

@ -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;

View File

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

View File

@ -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() {