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