2022-11-19 22:34:39 +00:00
|
|
|
|
|
|
|
import { Sequelize, } from "sequelize";
|
|
|
|
|
|
|
|
const dbConfig = require("../../config/database");
|
|
|
|
const sequelize = new Sequelize(dbConfig);
|
|
|
|
const { QueryTypes } = require('sequelize');
|
|
|
|
|
|
|
|
import { splitDateTime } from "../../helpers/SplitDateTime";
|
|
|
|
import format from 'date-fns/format';
|
|
|
|
import ptBR from 'date-fns/locale/pt-BR';
|
|
|
|
|
|
|
|
interface Request {
|
|
|
|
timeseconds: string | number;
|
|
|
|
status: string;
|
|
|
|
userId?: string | number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ListTicketTimeLife = async ({timeseconds, status, userId }: Request): Promise<any[]> => {
|
|
|
|
|
|
|
|
let tickets = []
|
|
|
|
|
|
|
|
let currentDate = format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR })
|
|
|
|
|
2022-12-08 19:28:03 +00:00
|
|
|
// console.log('------------------> currentDate: ', currentDate)
|
2022-11-19 22:34:39 +00:00
|
|
|
|
|
|
|
if (userId) {
|
|
|
|
// CONSULTANDO FILAS PELO ID DO USUARIO
|
|
|
|
tickets = await sequelize.query(`select user.id as user_id, user.name as user_name, t.id as ticket_id from Tickets as t inner join Users as user on
|
|
|
|
t.userId = user.id and user.name = 'botqueue' and t.status='${status}' and (TIMESTAMPDIFF(SECOND, t.updatedAt, '${currentDate}')) >= ${timeseconds};`, { type: QueryTypes.SELECT });
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// CONSULTANDO FILAS PELO USUARIO
|
|
|
|
tickets = await sequelize.query(`select id as ticket_id from Tickets where status='${status}' and
|
|
|
|
(TIMESTAMPDIFF(SECOND, updatedAt, '${currentDate}')) >= ${timeseconds};`, { type: QueryTypes.SELECT });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tickets;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ListTicketTimeLife;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|