W n8n
This commit is contained in:
parent
25157439c3
commit
3cb22a643f
@ -140,6 +140,19 @@ export async function POST(request: Request) {
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
// Verify that the creator exists
|
||||
const creator = await prisma.user.findUnique({
|
||||
where: { id: userId }
|
||||
});
|
||||
|
||||
if (!creator) {
|
||||
return NextResponse.json({
|
||||
error: 'Invalid creator ID',
|
||||
details: 'The specified creator does not exist',
|
||||
code: 'INVALID_CREATOR'
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
// Check if mission with same name exists
|
||||
const existingMission = await prisma.mission.findFirst({
|
||||
where: { name: body.name }
|
||||
@ -208,10 +221,11 @@ export async function POST(request: Request) {
|
||||
|
||||
return NextResponse.json(workflowResult);
|
||||
} catch (error) {
|
||||
console.error('Error triggering n8n workflow:', error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'Failed to create mission resources',
|
||||
details: 'The mission creation process failed. Please try again later.',
|
||||
details: error instanceof Error ? error.message : 'The mission creation process failed. Please try again later.',
|
||||
code: 'WORKFLOW_ERROR'
|
||||
},
|
||||
{ status: 500 }
|
||||
@ -220,6 +234,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
// Create mission directly (n8n request)
|
||||
try {
|
||||
const mission = await prisma.mission.create({
|
||||
data: {
|
||||
name: body.name,
|
||||
@ -283,6 +298,25 @@ export async function POST(request: Request) {
|
||||
message: 'Mission created successfully',
|
||||
mission
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error creating mission:', error);
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
if (error.code === 'P2003') {
|
||||
return NextResponse.json({
|
||||
error: 'Invalid reference',
|
||||
details: 'One or more referenced users do not exist',
|
||||
code: 'INVALID_REFERENCE'
|
||||
}, { status: 400 });
|
||||
}
|
||||
}
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: 'Failed to create mission',
|
||||
details: error instanceof Error ? error.message : String(error)
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error creating mission:', error);
|
||||
return NextResponse.json(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user