|
@@ -297,7 +297,16 @@ export async function avaliarPendentes({ limite = config.avaliacao.batchSize } =
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export async function listarAvaliacoes({ page = 1, pageSize = 20, setor, resolvido, sentimento, scoreMax } = {}) {
|
|
|
|
|
|
|
+// busca digitada: "07/11/2024" ou "2024-11-07" vira filtro pela data de abertura
|
|
|
|
|
+function parseDataBusca(termo) {
|
|
|
|
|
+ let m = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(termo);
|
|
|
|
|
+ if (m) return `${m[3]}-${m[2]}-${m[1]}`;
|
|
|
|
|
+ m = /^\d{4}-\d{2}-\d{2}$/.exec(termo);
|
|
|
|
|
+ if (m) return termo;
|
|
|
|
|
+ return null;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function listarAvaliacoes({ page = 1, pageSize = 20, setor, resolvido, sentimento, scoreMax, busca } = {}) {
|
|
|
const query = AtendimentoAvaliacao.query()
|
|
const query = AtendimentoAvaliacao.query()
|
|
|
.where("Avaliavel", true)
|
|
.where("Avaliavel", true)
|
|
|
.page(page - 1, pageSize)
|
|
.page(page - 1, pageSize)
|
|
@@ -307,11 +316,27 @@ export async function listarAvaliacoes({ page = 1, pageSize = 20, setor, resolvi
|
|
|
if (sentimento) query.where("Sentimento", sentimento);
|
|
if (sentimento) query.where("Sentimento", sentimento);
|
|
|
if (scoreMax !== undefined) query.where("ScoreAtendente", "<=", scoreMax);
|
|
if (scoreMax !== undefined) query.where("ScoreAtendente", "<=", scoreMax);
|
|
|
|
|
|
|
|
- if (setor) {
|
|
|
|
|
|
|
+ const termo = typeof busca === "string" ? busca.trim() : "";
|
|
|
|
|
+
|
|
|
|
|
+ if (setor || termo) {
|
|
|
query
|
|
query
|
|
|
.join("atendimentos as a", "a.Id", "atendimento_avaliacoes.AtendimentoId")
|
|
.join("atendimentos as a", "a.Id", "atendimento_avaliacoes.AtendimentoId")
|
|
|
- .where("a.Setor", setor)
|
|
|
|
|
.select("atendimento_avaliacoes.*");
|
|
.select("atendimento_avaliacoes.*");
|
|
|
|
|
+
|
|
|
|
|
+ if (setor) query.where("a.Setor", setor);
|
|
|
|
|
+
|
|
|
|
|
+ if (termo) {
|
|
|
|
|
+ const like = `%${termo.replace(/[\\%_]/g, (ch) => `\\${ch}`)}%`;
|
|
|
|
|
+ const data = parseDataBusca(termo);
|
|
|
|
|
+
|
|
|
|
|
+ query.leftJoin("atendimento_clientes as c", "c.Id", "a.ClienteId").where((qb) => {
|
|
|
|
|
+ qb.where("a.Codigo", "like", like)
|
|
|
|
|
+ .orWhere("c.Nome", "like", like)
|
|
|
|
|
+ // Atendentes é JSON text (["Luiz","Carla"]) — LIKE cobre busca por nome
|
|
|
|
|
+ .orWhere("atendimento_avaliacoes.Atendentes", "like", like);
|
|
|
|
|
+ if (data) qb.orWhereRaw("DATE(a.Abertura) = ?", [data]);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const { results, total } = await query;
|
|
const { results, total } = await query;
|