6755-restoreRefactor #2158
|
@ -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;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"changeModel": {
|
||||
"changedModel": {
|
||||
"type": "string"
|
||||
},
|
||||
"oldInstance": {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue