backpack1098B
Convex Community3y ago
4 replies
backpack1098

Possible to optionally filter an arg?

I've skimmed thru search.convex.dev but couldnt find any answer. is it possible to optionally filter an arg?
export const listTasks = query({
  args: {
    dateBegin: v.optional(v.string()),
  },

  handler: async (ctx, args) => {
    const tasks = await ctx.db
      .query(TASK_DB)
      .filter((q) =>
        q.and(
          args.dateBegin !== "" 
            ? q.gte(q.field("scheduledTime"), Number(args.dateBegin) * 1000) 
            : q.truthy(), // is this available?
          ...
        )
      )
      .collect()
  }
})

thanks!
Was this page helpful?