lots of changes
This commit is contained in:
@@ -126,3 +126,29 @@ export const listByProject = query({
|
||||
.collect();
|
||||
},
|
||||
});
|
||||
|
||||
export const getLatestByDataSource = query({
|
||||
args: {
|
||||
dataSourceId: v.id("dataSources"),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const userId = await getAuthUserId(ctx);
|
||||
if (!userId) return null;
|
||||
|
||||
const dataSource = await ctx.db.get(args.dataSourceId);
|
||||
if (!dataSource) return null;
|
||||
|
||||
const project = await ctx.db.get(dataSource.projectId);
|
||||
if (!project || project.userId !== userId) return null;
|
||||
|
||||
const jobs = await ctx.db
|
||||
.query("analysisJobs")
|
||||
.withIndex("by_dataSource_createdAt", (q) =>
|
||||
q.eq("dataSourceId", args.dataSourceId)
|
||||
)
|
||||
.order("desc")
|
||||
.take(1);
|
||||
|
||||
return jobs[0] ?? null;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user