feat: db connection and query
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
eccbd942f7
commit
538c04e8c5
|
@ -1,4 +1,6 @@
|
||||||
const jsdom = require('jsdom');
|
const jsdom = require('jsdom');
|
||||||
|
const mysql = require('mysql');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('closeTicket', {
|
Self.remoteMethodCtx('closeTicket', {
|
||||||
description: 'Close tickets without response from the user',
|
description: 'Close tickets without response from the user',
|
||||||
|
@ -19,17 +21,37 @@ module.exports = Self => {
|
||||||
|
|
||||||
const ostUri = `${config.host}/login.php`;
|
const ostUri = `${config.host}/login.php`;
|
||||||
|
|
||||||
// const tickets = await models.OsTicket.rawSql(`
|
const con = mysql.createConnection({
|
||||||
// SELECT t.ticket_id AS id, t.number, ua.username, td.subject
|
host: 'localhost',
|
||||||
// FROM ost_ticket t
|
user: 'osticket',
|
||||||
// JOIN ost_user_account ua ON t.user_id = ua.user_id
|
password: 'osticket',
|
||||||
// JOIN ost_ticket__cdata td ON t.ticket_id = td.ticket_id
|
port: 40003
|
||||||
// JOIN ost_ticket_priority tp ON td.priority = tp.priority_id
|
});
|
||||||
// LEFT JOIN ost_department dept ON dept.id = t.dept_id
|
|
||||||
// WHERE tp.priority = 'emergency'
|
const sql = `SELECT ot.ticket_id, ot.number
|
||||||
// AND (t.staff_id = 0 AND t.team_id = 0)
|
FROM osticket.ost_ticket ot
|
||||||
// AND dept.code = 'IT'
|
JOIN osticket.ost_thread ot2 ON ot2.object_id = ot.ticket_id AND ot2.object_type = 'T'
|
||||||
// `);
|
JOIN (
|
||||||
|
SELECT ote.thread_id, MAX(ote.created) created, MAX(ote.updated) updated
|
||||||
|
FROM osticket.ost_thread_entry ote
|
||||||
|
WHERE ote.staff_id != 0 AND ote.type = 'R'
|
||||||
|
GROUP BY ote.thread_id
|
||||||
|
) sub ON sub.thread_id = ot2.id
|
||||||
|
WHERE ot.isanswered = 1
|
||||||
|
AND status_id IN (${config.oldStatusId})
|
||||||
|
AND IF(sub.updated > sub.created, sub.updated, sub.created) < DATE_SUB(CURDATE(), INTERVAL ${config.day} DAY)`;
|
||||||
|
|
||||||
|
let ticketsId = [];
|
||||||
|
con.connect(err => {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log('Connected!');
|
||||||
|
con.query(sql, (err, results) => {
|
||||||
|
if (err) throw err;
|
||||||
|
for (const result of results)
|
||||||
|
ticketsId.push(result.ticket_id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
await requestToken();
|
await requestToken();
|
||||||
|
|
||||||
async function requestToken() {
|
async function requestToken() {
|
||||||
|
@ -70,24 +92,26 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function close(token, secondCookie) {
|
async function close(token, secondCookie) {
|
||||||
const ostUri = `${config.host}/ajax.php/tickets/47460/status`;
|
for (const ticketId of ticketsId) {
|
||||||
const data = {
|
const ostUri = `${config.host}/ajax.php/tickets/${ticketId}/status`;
|
||||||
status_id: config.statusId,
|
const data = {
|
||||||
comments: undefined,
|
status_id: config.newStatusId,
|
||||||
undefined: config.action
|
comments: undefined,
|
||||||
};
|
undefined: config.action
|
||||||
const params = {
|
};
|
||||||
method: 'POST',
|
const params = {
|
||||||
body: new URLSearchParams(data),
|
method: 'POST',
|
||||||
headers: {
|
body: new URLSearchParams(data),
|
||||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
headers: {
|
||||||
'X-CSRFToken': token,
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||||
'Cookie': secondCookie
|
'X-CSRFToken': token,
|
||||||
}
|
'Cookie': secondCookie
|
||||||
};
|
}
|
||||||
const response = await fetch(ostUri, params);
|
};
|
||||||
console.log(response.statusText);
|
const response = await fetch(ostUri, params);
|
||||||
// return fetch(ostUri, params);
|
console.log(response.statusText);
|
||||||
|
// return fetch(ostUri, params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,11 +21,17 @@
|
||||||
"password": {
|
"password": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"statusId": {
|
"oldStatusId": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"newStatusId": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"day": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,13 +1,15 @@
|
||||||
CREATE TABLE `vn`.`osTicketConfig` (
|
CREATE TABLE `osTicketConfig` (
|
||||||
`id` int(11) NOT NULL,
|
`id` int(11) NOT NULL,
|
||||||
`host` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
`host` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
||||||
`user` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
`user` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
||||||
`password` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
`password` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
||||||
`statusId` int(11) DEFAULT NULL,
|
`oldStatusId` int(11) DEFAULT NULL,
|
||||||
|
`newStatusId` int(11) DEFAULT NULL,
|
||||||
`action` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
`action` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
||||||
|
`day` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||||
|
|
||||||
INSERT INTO `vn`.`osTicketConfig`(id, host, `user`, password, statusId, `action`)
|
INSERT INTO `vn`.`osTicketConfig`(id, host, `user`, password, statusId, `action`)
|
||||||
VALUES
|
VALUES
|
||||||
(0, 'https://cau.verdnatura.es/scp', 'vicent', 'llopis.19263', 3, 'Cerrar');
|
(0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', 1, 3, 'Cerrar', 60);
|
||||||
|
|
Loading…
Reference in New Issue