export const scheduledDelete = mutation({
args: { id: v.id("thing") },
handler: async (ctx, args) => {
const userId = await getUserId(ctx);
const thing = await ctx.db.get(args.id);
if (!thing) throw new Error(`Dream with ID ${args.id} not found.`);
if (userId !== thing.userId) throw new Error("Unauthorized access.");
const taskId = await ctx.scheduler.runAfter(
10 * 1000,
internal.mutations.deleteThing,
{ id: thing._id }
);
return taskId;
},
});
export const deleteThing = internalMutation({
args: { id: v.id("thing") },
handler: async (ctx, args) => {
await ctx.db.delete(args.id);
},
});
export const cancelScheduledDeletion = mutation({
args: { taskId: v.id("_scheduled_functions") },
handler: async (ctx, args) => {
await ctx.scheduler.cancel(args.taskId);
},
});
export const scheduledDelete = mutation({
args: { id: v.id("thing") },
handler: async (ctx, args) => {
const userId = await getUserId(ctx);
const thing = await ctx.db.get(args.id);
if (!thing) throw new Error(`Dream with ID ${args.id} not found.`);
if (userId !== thing.userId) throw new Error("Unauthorized access.");
const taskId = await ctx.scheduler.runAfter(
10 * 1000,
internal.mutations.deleteThing,
{ id: thing._id }
);
return taskId;
},
});
export const deleteThing = internalMutation({
args: { id: v.id("thing") },
handler: async (ctx, args) => {
await ctx.db.delete(args.id);
},
});
export const cancelScheduledDeletion = mutation({
args: { taskId: v.id("_scheduled_functions") },
handler: async (ctx, args) => {
await ctx.scheduler.cancel(args.taskId);
},
});