feat: sync convex companies and dashboard metrics
This commit is contained in:
parent
4f52114b48
commit
7a3eca9361
10 changed files with 356 additions and 19 deletions
|
|
@ -85,3 +85,24 @@ export const ensureProvisioned = mutation({
|
|||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const removeBySlug = mutation({
|
||||
args: {
|
||||
tenantId: v.string(),
|
||||
slug: v.string(),
|
||||
},
|
||||
handler: async (ctx, { tenantId, slug }) => {
|
||||
const normalizedSlug = normalizeSlug(slug) ?? slug
|
||||
const existing = await ctx.db
|
||||
.query("companies")
|
||||
.withIndex("by_tenant_slug", (q) => q.eq("tenantId", tenantId).eq("slug", normalizedSlug))
|
||||
.unique()
|
||||
|
||||
if (!existing) {
|
||||
return { removed: false }
|
||||
}
|
||||
|
||||
await ctx.db.delete(existing._id)
|
||||
return { removed: true }
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -347,6 +347,22 @@ export const dashboardOverview = query({
|
|||
|
||||
const trend = percentageChange(newTickets.length, previousTickets.length);
|
||||
|
||||
const inProgressCurrent = tickets.filter((ticket) => {
|
||||
if (!ticket.firstResponseAt) return false;
|
||||
const status = normalizeStatus(ticket.status);
|
||||
if (status === "RESOLVED") return false;
|
||||
return !ticket.resolvedAt;
|
||||
});
|
||||
|
||||
const inProgressPrevious = tickets.filter((ticket) => {
|
||||
if (!ticket.firstResponseAt || ticket.firstResponseAt >= lastDayStart) return false;
|
||||
if (ticket.resolvedAt && ticket.resolvedAt < lastDayStart) return false;
|
||||
const status = normalizeStatus(ticket.status);
|
||||
return status !== "RESOLVED" || !ticket.resolvedAt;
|
||||
});
|
||||
|
||||
const inProgressTrend = percentageChange(inProgressCurrent.length, inProgressPrevious.length);
|
||||
|
||||
const lastWindowStart = now - 7 * ONE_DAY_MS;
|
||||
const previousWindowStart = now - 14 * ONE_DAY_MS;
|
||||
|
||||
|
|
@ -396,6 +412,11 @@ export const dashboardOverview = query({
|
|||
previous24h: previousTickets.length,
|
||||
trendPercentage: trend,
|
||||
},
|
||||
inProgress: {
|
||||
current: inProgressCurrent.length,
|
||||
previousSnapshot: inProgressPrevious.length,
|
||||
trendPercentage: inProgressTrend,
|
||||
},
|
||||
firstResponse: {
|
||||
averageMinutes: averageWindow,
|
||||
previousAverageMinutes: averagePrevious,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue