feat: improve requester combobox and admin cleanup flows
This commit is contained in:
parent
788f6928a1
commit
37c32149a6
13 changed files with 923 additions and 180 deletions
|
|
@ -1638,6 +1638,41 @@ export const changeRequester = mutation({
|
|||
},
|
||||
})
|
||||
|
||||
export const purgeTicketsForUsers = mutation({
|
||||
args: {
|
||||
tenantId: v.string(),
|
||||
actorId: v.id("users"),
|
||||
userIds: v.array(v.id("users")),
|
||||
},
|
||||
handler: async (ctx, { tenantId, actorId, userIds }) => {
|
||||
await requireAdmin(ctx, actorId, tenantId)
|
||||
if (userIds.length === 0) {
|
||||
return { deleted: 0 }
|
||||
}
|
||||
const uniqueIds = Array.from(new Set(userIds.map((id) => id)))
|
||||
let deleted = 0
|
||||
for (const userId of uniqueIds) {
|
||||
const requesterTickets = await ctx.db
|
||||
.query("tickets")
|
||||
.withIndex("by_tenant_requester", (q) => q.eq("tenantId", tenantId).eq("requesterId", userId))
|
||||
.collect()
|
||||
for (const ticket of requesterTickets) {
|
||||
await ctx.db.delete(ticket._id)
|
||||
deleted += 1
|
||||
}
|
||||
const assigneeTickets = await ctx.db
|
||||
.query("tickets")
|
||||
.withIndex("by_tenant_assignee", (q) => q.eq("tenantId", tenantId).eq("assigneeId", userId))
|
||||
.collect()
|
||||
for (const ticket of assigneeTickets) {
|
||||
await ctx.db.delete(ticket._id)
|
||||
deleted += 1
|
||||
}
|
||||
}
|
||||
return { deleted }
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
export const changeQueue = mutation({
|
||||
args: { ticketId: v.id("tickets"), queueId: v.id("queues"), actorId: v.id("users") },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue