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

@ -4,10 +4,23 @@ import { v } from "convex/values";
export const ensureDefaults = mutation({
args: { tenantId: v.string() },
handler: async (ctx, { tenantId }) => {
const existing = await ctx.db
let existing = await ctx.db
.query("queues")
.withIndex("by_tenant", (q) => q.eq("tenantId", tenantId))
.collect();
existing = await Promise.all(
existing.map(async (queue) => {
if (queue.name === "Suporte N1" || queue.slug === "suporte-n1") {
await ctx.db.patch(queue._id, { name: "Chamados", slug: "chamados" });
return (await ctx.db.get(queue._id)) ?? queue;
}
if (queue.name === "Suporte N2" || queue.slug === "suporte-n2") {
await ctx.db.patch(queue._id, { name: "Laboratório", slug: "laboratorio" });
return (await ctx.db.get(queue._id)) ?? queue;
}
return queue;
})
);
if (existing.length === 0) {
const queues = [
{ name: "Chamados", slug: "chamados" },