import { v } from 'convex/values'; import { query } from './_generated/server'; import { getOwnedSpoon, getRequiredUserId } from './model'; export const listRecent = query({ args: { limit: v.optional(v.number()) }, handler: async (ctx, { limit }) => { const ownerId = await getRequiredUserId(ctx); const runs = await ctx.db .query('syncRuns') .withIndex('by_owner', (q) => q.eq('ownerId', ownerId)) .order('desc') .take(limit ?? 25); return runs; }, }); export const listForSpoon = query({ args: { spoonId: v.id('spoons'), limit: v.optional(v.number()) }, handler: async (ctx, { spoonId, limit }) => { const ownerId = await getRequiredUserId(ctx); await getOwnedSpoon(ctx, spoonId, ownerId); return await ctx.db .query('syncRuns') .withIndex('by_spoon', (q) => q.eq('spoonId', spoonId)) .order('desc') .take(limit ?? 25); }, });