34 lines
959 B
TypeScript
34 lines
959 B
TypeScript
import { asErrorMessage, jsonError } from '@/lib/server/http';
|
|
import { requireAuthenticatedSession } from '@/lib/server/auth-session';
|
|
import { enqueueTask } from '@/lib/server/tasks';
|
|
|
|
type Context = {
|
|
params: Promise<{ accessionNumber: string }>;
|
|
};
|
|
|
|
export async function POST(_request: Request, context: Context) {
|
|
const { session, response } = await requireAuthenticatedSession();
|
|
if (response) {
|
|
return response;
|
|
}
|
|
|
|
try {
|
|
const { accessionNumber } = await context.params;
|
|
|
|
if (!accessionNumber || accessionNumber.trim().length < 4) {
|
|
return jsonError('Invalid accession number');
|
|
}
|
|
|
|
const task = await enqueueTask({
|
|
userId: session.user.id,
|
|
taskType: 'analyze_filing',
|
|
payload: { accessionNumber: accessionNumber.trim() },
|
|
priority: 65
|
|
});
|
|
|
|
return Response.json({ task });
|
|
} catch (error) {
|
|
return jsonError(asErrorMessage(error, 'Failed to queue filing analysis task'));
|
|
}
|
|
}
|