fix: normalize queue labels
This commit is contained in:
parent
dee31117d3
commit
e833888a3a
4 changed files with 103 additions and 16 deletions
|
|
@ -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" },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue