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;
},
});
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;
},
});