Merge branch 'master' into Hotfix-crear-report-Factura-Electronica
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
commit
1c1cc93ef4
|
@ -25,10 +25,10 @@ module.exports = Self => {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const con = mysql.createConnection({
|
const con = mysql.createConnection({
|
||||||
host: `${config.hostDb}`,
|
host: config.hostDb,
|
||||||
user: `${config.userDb}`,
|
user: config.userDb,
|
||||||
password: `${config.passwordDb}`,
|
password: config.passwordDb,
|
||||||
port: `${config.portDb}`
|
port: config.portDb
|
||||||
});
|
});
|
||||||
|
|
||||||
const sql = `SELECT ot.ticket_id, ot.number
|
const sql = `SELECT ot.ticket_id, ot.number
|
||||||
|
@ -38,23 +38,23 @@ module.exports = Self => {
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT ote.thread_id, MAX(ote.created) created, MAX(ote.updated) updated
|
SELECT ote.thread_id, MAX(ote.created) created, MAX(ote.updated) updated
|
||||||
FROM osticket.ost_thread_entry ote
|
FROM osticket.ost_thread_entry ote
|
||||||
WHERE ote.staff_id != 0 AND ote.type = 'R'
|
WHERE ote.staff_id AND ote.type = 'R'
|
||||||
GROUP BY ote.thread_id
|
GROUP BY ote.thread_id
|
||||||
) sub ON sub.thread_id = ot2.id
|
) sub ON sub.thread_id = ot2.id
|
||||||
WHERE ot.isanswered = 1
|
WHERE ot.isanswered
|
||||||
AND ots.state = '${config.oldStatus}'
|
AND ots.state = ?
|
||||||
AND IF(sub.updated > sub.created, sub.updated, sub.created) < DATE_SUB(CURDATE(), INTERVAL ${config.day} DAY)`;
|
AND IF(sub.updated > sub.created, sub.updated, sub.created) < DATE_SUB(CURDATE(), INTERVAL ? DAY)`;
|
||||||
|
|
||||||
let ticketsId = [];
|
const ticketsId = [];
|
||||||
con.connect(err => {
|
con.connect(err => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
con.query(sql, (err, results) => {
|
con.query(sql, [config.oldStatus, config.day],
|
||||||
|
(err, results) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
for (const result of results)
|
for (const result of results)
|
||||||
ticketsId.push(result.ticket_id);
|
ticketsId.push(result.ticket_id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await getRequestToken();
|
await getRequestToken();
|
||||||
|
|
||||||
async function getRequestToken() {
|
async function getRequestToken() {
|
||||||
|
@ -94,24 +94,9 @@ module.exports = Self => {
|
||||||
await close(token, secondCookie);
|
await close(token, secondCookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLockCode(token, secondCookie, ticketId) {
|
|
||||||
const ostUri = `${config.host}/ajax.php/lock/ticket/${ticketId}`;
|
|
||||||
const params = {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'X-CSRFToken': token,
|
|
||||||
'Cookie': secondCookie
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const response = await fetch(ostUri, params);
|
|
||||||
const body = await response.text();
|
|
||||||
const json = JSON.parse(body);
|
|
||||||
|
|
||||||
return json.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function close(token, secondCookie) {
|
async function close(token, secondCookie) {
|
||||||
for (const ticketId of ticketsId) {
|
for (const ticketId of ticketsId) {
|
||||||
|
try {
|
||||||
const lockCode = await getLockCode(token, secondCookie, ticketId);
|
const lockCode = await getLockCode(token, secondCookie, ticketId);
|
||||||
let form = new FormData();
|
let form = new FormData();
|
||||||
form.append('__CSRFToken__', token);
|
form.append('__CSRFToken__', token);
|
||||||
|
@ -133,8 +118,29 @@ module.exports = Self => {
|
||||||
'Cookie': secondCookie
|
'Cookie': secondCookie
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return fetch(ostUri, params);
|
await fetch(ostUri, params);
|
||||||
|
} catch (e) {
|
||||||
|
const err = new Error(`${ticketId} Ticket close failed: ${e.message}`);
|
||||||
|
err.stack += e.stack;
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getLockCode(token, secondCookie, ticketId) {
|
||||||
|
const ostUri = `${config.host}/ajax.php/lock/ticket/${ticketId}`;
|
||||||
|
const params = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-CSRFToken': token,
|
||||||
|
'Cookie': secondCookie
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const response = await fetch(ostUri, params);
|
||||||
|
const body = await response.text();
|
||||||
|
const json = JSON.parse(body);
|
||||||
|
|
||||||
|
return json.code;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,6 +24,8 @@ module.exports = Self => {
|
||||||
const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions);
|
const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions);
|
||||||
const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions);
|
const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions);
|
||||||
const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions);
|
const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions);
|
||||||
|
if (!workerDepartment) return false;
|
||||||
|
|
||||||
const usesMana = departments.find(department => department.id == workerDepartment.departmentFk);
|
const usesMana = departments.find(department => department.id == workerDepartment.departmentFk);
|
||||||
|
|
||||||
return usesMana ? true : false;
|
return usesMana ? true : false;
|
||||||
|
|
Loading…
Reference in New Issue