a
This commit is contained in:
@@ -41,6 +41,22 @@ export const getLatestByDataSource = query({
|
||||
},
|
||||
});
|
||||
|
||||
export const getById = query({
|
||||
args: { analysisId: v.id("analyses") },
|
||||
handler: async (ctx, { analysisId }) => {
|
||||
const userId = await getAuthUserId(ctx);
|
||||
if (!userId) return null;
|
||||
|
||||
const analysis = await ctx.db.get(analysisId);
|
||||
if (!analysis) return null;
|
||||
|
||||
const project = await ctx.db.get(analysis.projectId);
|
||||
if (!project || project.userId !== userId) return null;
|
||||
|
||||
return analysis;
|
||||
},
|
||||
});
|
||||
|
||||
export const createAnalysis = mutation({
|
||||
args: {
|
||||
projectId: v.id("projects"),
|
||||
@@ -141,7 +157,7 @@ export const createAnalysis = mutation({
|
||||
throw new Error("Project not found or unauthorized");
|
||||
}
|
||||
|
||||
return await ctx.db.insert("analyses", {
|
||||
const analysisId = await ctx.db.insert("analyses", {
|
||||
projectId: args.projectId,
|
||||
dataSourceId: args.dataSourceId,
|
||||
createdAt: Date.now(),
|
||||
@@ -160,5 +176,38 @@ export const createAnalysis = mutation({
|
||||
dorkQueries: args.analysis.dorkQueries,
|
||||
scrapedAt: args.analysis.scrapedAt,
|
||||
});
|
||||
|
||||
const now = Date.now();
|
||||
const sections = [
|
||||
{
|
||||
sectionKey: "profile",
|
||||
items: {
|
||||
productName: args.analysis.productName,
|
||||
tagline: args.analysis.tagline,
|
||||
description: args.analysis.description,
|
||||
category: args.analysis.category,
|
||||
positioning: args.analysis.positioning,
|
||||
},
|
||||
},
|
||||
{ sectionKey: "features", items: args.analysis.features },
|
||||
{ sectionKey: "competitors", items: args.analysis.competitors },
|
||||
{ sectionKey: "keywords", items: args.analysis.keywords },
|
||||
{ sectionKey: "problems", items: args.analysis.problemsSolved },
|
||||
{ sectionKey: "personas", items: args.analysis.personas },
|
||||
{ sectionKey: "useCases", items: args.analysis.useCases },
|
||||
{ sectionKey: "dorkQueries", items: args.analysis.dorkQueries },
|
||||
];
|
||||
|
||||
for (const section of sections) {
|
||||
await ctx.db.insert("analysisSections", {
|
||||
analysisId,
|
||||
sectionKey: section.sectionKey,
|
||||
items: section.items,
|
||||
source: args.analysis.analysisVersion === "manual" ? "manual" : "ai",
|
||||
updatedAt: now,
|
||||
});
|
||||
}
|
||||
|
||||
return analysisId;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user