24 lines
989 B
TypeScript
24 lines
989 B
TypeScript
import { query } from "./_generated/server";
|
|
import { v } from "convex/values";
|
|
|
|
export const summary = query({
|
|
args: { tenantId: v.string() },
|
|
handler: async (ctx, { tenantId }) => {
|
|
const queues = await ctx.db.query("queues").withIndex("by_tenant", (q) => q.eq("tenantId", tenantId)).collect();
|
|
// Compute counts per queue
|
|
const result = await Promise.all(
|
|
queues.map(async (qItem) => {
|
|
const pending = await ctx.db
|
|
.query("tickets")
|
|
.withIndex("by_tenant_queue", (q) => q.eq("tenantId", tenantId).eq("queueId", qItem._id))
|
|
.collect();
|
|
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 result;
|
|
},
|
|
});
|
|
|