refine queue metrics and devices ui
This commit is contained in:
parent
1e45324460
commit
c2acd65764
11 changed files with 181 additions and 116 deletions
|
|
@ -1,14 +1,5 @@
|
|||
import { cronJobs } from "convex/server"
|
||||
import { api } from "./_generated/api"
|
||||
|
||||
const crons = cronJobs()
|
||||
|
||||
// Check hourly and the action will gate by America/Sao_Paulo hour
|
||||
crons.interval(
|
||||
"hours-usage-alerts-hourly",
|
||||
{ hours: 1 },
|
||||
api.alerts_actions.sendHoursUsageAlerts,
|
||||
{}
|
||||
)
|
||||
|
||||
export default crons
|
||||
|
|
|
|||
|
|
@ -113,20 +113,39 @@ export const summary = query({
|
|||
const queues = await ctx.db.query("queues").withIndex("by_tenant", (q) => q.eq("tenantId", tenantId)).collect();
|
||||
const result = await Promise.all(
|
||||
queues.map(async (qItem) => {
|
||||
const pending = await ctx.db
|
||||
const tickets = await ctx.db
|
||||
.query("tickets")
|
||||
.withIndex("by_tenant_queue", (q) => q.eq("tenantId", tenantId).eq("queueId", qItem._id))
|
||||
.collect();
|
||||
const waiting = pending.filter((t) => {
|
||||
const status = normalizeStatus(t.status);
|
||||
return status === "PENDING" || status === "PAUSED";
|
||||
}).length;
|
||||
const open = pending.filter((t) => {
|
||||
const status = normalizeStatus(t.status);
|
||||
return status !== "RESOLVED";
|
||||
}).length;
|
||||
const breached = 0;
|
||||
return { id: qItem._id, name: renameQueueString(qItem.name), pending: open, waiting, breached };
|
||||
let pending = 0;
|
||||
let inProgress = 0;
|
||||
let paused = 0;
|
||||
let breached = 0;
|
||||
const now = Date.now();
|
||||
for (const ticket of tickets) {
|
||||
const status = normalizeStatus(ticket.status);
|
||||
if (status === "PENDING") {
|
||||
pending += 1;
|
||||
} else if (status === "AWAITING_ATTENDANCE") {
|
||||
inProgress += 1;
|
||||
} else if (status === "PAUSED") {
|
||||
paused += 1;
|
||||
}
|
||||
if (status !== "RESOLVED") {
|
||||
const dueAt = typeof ticket.dueAt === "number" ? ticket.dueAt : null;
|
||||
if (dueAt && dueAt < now) {
|
||||
breached += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
id: qItem._id,
|
||||
name: renameQueueString(qItem.name),
|
||||
pending,
|
||||
inProgress,
|
||||
paused,
|
||||
breached,
|
||||
};
|
||||
})
|
||||
);
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue