W n8n
This commit is contained in:
parent
7c08add31f
commit
81b799668e
File diff suppressed because one or more lines are too long
@ -25,6 +25,7 @@ interface MissionCreateInput {
|
||||
rocketchatChannelId?: string;
|
||||
gitRepoUrl?: string;
|
||||
penpotProjectId?: string;
|
||||
creatorId?: string;
|
||||
}
|
||||
|
||||
interface MissionUserInput {
|
||||
@ -140,9 +141,15 @@ export async function POST(request: Request) {
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
// Verify that the creator exists BEFORE triggering n8n workflow
|
||||
// Check if this is a request from n8n
|
||||
const isN8nRequest = request.headers.get('x-api-key') === process.env.N8N_API_KEY;
|
||||
|
||||
// Get the creator ID from the appropriate source
|
||||
const creatorId = isN8nRequest ? body.creatorId : userId;
|
||||
|
||||
// Verify creator exists for both n8n and non-n8n requests
|
||||
const creator = await prisma.user.findUnique({
|
||||
where: { id: userId }
|
||||
where: { id: creatorId }
|
||||
});
|
||||
|
||||
if (!creator) {
|
||||
@ -196,11 +203,8 @@ export async function POST(request: Request) {
|
||||
}, { status: 409 });
|
||||
}
|
||||
|
||||
// Check if this is a request from n8n
|
||||
const isN8nRequest = request.headers.get('x-api-key') === process.env.N8N_API_KEY;
|
||||
|
||||
// Handle n8n workflow
|
||||
if (!isN8nRequest) {
|
||||
// Trigger n8n workflow
|
||||
const n8nService = new N8nService();
|
||||
|
||||
// Prepare the data for n8n
|
||||
@ -217,7 +221,7 @@ export async function POST(request: Request) {
|
||||
profils: Array.isArray(body.profils) ? body.profils : [],
|
||||
guardians: body.guardians || {},
|
||||
volunteers: Array.isArray(body.volunteers) ? body.volunteers : [],
|
||||
creatorId: userId, // Use the verified userId
|
||||
creatorId: userId,
|
||||
config: {
|
||||
N8N_API_KEY: process.env.N8N_API_KEY,
|
||||
MISSION_API_URL: process.env.NEXT_PUBLIC_API_URL || 'https://api.slm-lab.net/api'
|
||||
@ -311,7 +315,7 @@ export async function POST(request: Request) {
|
||||
services: Array.isArray(body.services) ? body.services.filter(Boolean) : [],
|
||||
profils: Array.isArray(body.profils) ? body.profils.filter(Boolean) : [],
|
||||
participation: body.participation || 'default',
|
||||
creatorId: userId,
|
||||
creatorId: creatorId,
|
||||
logo: body.logo || null,
|
||||
leantimeProjectId: body.leantimeProjectId || null,
|
||||
outlineCollectionId: body.documentationCollectionId || null,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user