import { query } from "./_generated/server"; import { v } from "convex/values"; export const list = query({ args: { status: v.optional(v.union(v.literal("open"), v.literal("closed"))) }, handler: async (ctx, args) => { if (args.status) { return await ctx.db .query("posts") .withIndex("by_status", (q) => q.eq("status", args.status!)) .order("desc") .collect(); } return await ctx.db.query("posts").order("desc").collect(); }, }); export const getByCustomer = query({ args: { customerId: v.id("users") }, handler: async (ctx, args) => { return await ctx.db .query("posts") .withIndex("by_customer", (q) => q.eq("customerId", args.customerId)) .collect(); }, });