fix: normalize queue labels

This commit is contained in:
esdrasrenan 2025-10-05 00:36:59 -03:00
parent dee31117d3
commit e833888a3a
4 changed files with 103 additions and 16 deletions

View file

@ -1,6 +1,20 @@
import { query } from "./_generated/server";
import { v } from "convex/values";
const QUEUE_RENAME_LOOKUP: Record<string, string> = {
"Suporte N1": "Chamados",
"suporte-n1": "Chamados",
"Suporte N2": "Laboratório",
"suporte-n2": "Laboratório",
};
function renameQueueString(value: string) {
const direct = QUEUE_RENAME_LOOKUP[value];
if (direct) return direct;
const normalizedKey = value.replace(/\s+/g, "-").toLowerCase();
return QUEUE_RENAME_LOOKUP[normalizedKey] ?? value;
}
export const summary = query({
args: { tenantId: v.string() },
handler: async (ctx, { tenantId }) => {
@ -15,7 +29,7 @@ export const summary = query({
const waiting = pending.filter((t) => t.status === "PENDING" || t.status === "ON_HOLD").length;
const open = pending.filter((t) => t.status !== "RESOLVED" && t.status !== "CLOSED").length;
const breached = 0; // Placeholder, SLAs later
return { id: qItem._id, name: qItem.name, pending: open, waiting, breached };
return { id: qItem._id, name: renameQueueString(qItem.name), pending: open, waiting, breached };
})
);
return result;