Web Dev CodyW
Convex Community3y ago
11 replies
Web Dev Cody

No clue why I'm getting this error

import { v } from 'convex/values';

import { internal } from '../_generated/api';
import { action } from '../_generated/server';

export const createPlan = action({
  args: { projectIdea: v.string(), targetUser: v.string() },
  handler: async (ctx, args) => {
    const user = await ctx.auth.getUserIdentity();
    const userId = user?.subject;

    if (!userId) {
      return {
        error: 'no user id was found',
      };
    }

    try {
      await ctx.runMutation(internal.users.decrementCredits, {
        userId,
        amount: 1,
      });
    } catch (err) {
      return {
        error: 'not enough credits',
      };
    }

  // this is saying 'planId' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)

    const planId = await ctx.runMutation(
      internal.plans.mutations.createInitialPlan,
      {
        projectIdea: args.projectIdea,
        targetUser: args.targetUser,
        userId: userId,
      },
    );

    await ctx.scheduler.runAfter(
      0,
      internal.plans.sections.names.generateProductNamesAction,
      {
        planId,
      },
    );

    await ctx.scheduler.runAfter(
      0,
      internal.plans.sections.colors.generateColorPaletteAction,
      {
        planId,
      },
    );

    await ctx.scheduler.runAfter(
      10000,
      internal.plans.sections.designs.generateDesignsAction,
      {
        planId,
      },
    );

    return planId;
  },
});
Screenshot_2024-01-11_at_7.12.00_PM.png
Was this page helpful?