ŠtosdenferŠ
Convex Community7mo ago
35 replies
Štosdenfer

Check if document exists once?

I want to check if a document exists once from my client.

I'm running a document management app and before I upload the documents to uploadthing, I want to check if a task containing said documents exists.

I created a query, but when using it via "useQuery" I have to define the argument at hook call, but I don't know it until the user submitted it.

export const checkTaskExists = query({
  args: {
    taskFullId: v.string(),
  },
  handler: async (ctx, args) => {
    const task = await ctx.db
      .query("tasks")
      .withIndex("by_taskFullId", (q) => q.eq("taskFullId", args.taskFullId))
      .first();
    return !!task;
  },
});


Now I somehow want to call
checkTaskExists({taskFullId)
from my onSubmit function

Is that somehow possibe? Maybe via Actions?
Was this page helpful?