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;
|
rocketchatChannelId?: string;
|
||||||
gitRepoUrl?: string;
|
gitRepoUrl?: string;
|
||||||
penpotProjectId?: string;
|
penpotProjectId?: string;
|
||||||
|
creatorId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MissionUserInput {
|
interface MissionUserInput {
|
||||||
@ -140,9 +141,15 @@ export async function POST(request: Request) {
|
|||||||
}, { status: 400 });
|
}, { 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({
|
const creator = await prisma.user.findUnique({
|
||||||
where: { id: userId }
|
where: { id: creatorId }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!creator) {
|
if (!creator) {
|
||||||
@ -196,11 +203,8 @@ export async function POST(request: Request) {
|
|||||||
}, { status: 409 });
|
}, { status: 409 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is a request from n8n
|
// Handle n8n workflow
|
||||||
const isN8nRequest = request.headers.get('x-api-key') === process.env.N8N_API_KEY;
|
|
||||||
|
|
||||||
if (!isN8nRequest) {
|
if (!isN8nRequest) {
|
||||||
// Trigger n8n workflow
|
|
||||||
const n8nService = new N8nService();
|
const n8nService = new N8nService();
|
||||||
|
|
||||||
// Prepare the data for n8n
|
// Prepare the data for n8n
|
||||||
@ -217,7 +221,7 @@ export async function POST(request: Request) {
|
|||||||
profils: Array.isArray(body.profils) ? body.profils : [],
|
profils: Array.isArray(body.profils) ? body.profils : [],
|
||||||
guardians: body.guardians || {},
|
guardians: body.guardians || {},
|
||||||
volunteers: Array.isArray(body.volunteers) ? body.volunteers : [],
|
volunteers: Array.isArray(body.volunteers) ? body.volunteers : [],
|
||||||
creatorId: userId, // Use the verified userId
|
creatorId: userId,
|
||||||
config: {
|
config: {
|
||||||
N8N_API_KEY: process.env.N8N_API_KEY,
|
N8N_API_KEY: process.env.N8N_API_KEY,
|
||||||
MISSION_API_URL: process.env.NEXT_PUBLIC_API_URL || 'https://api.slm-lab.net/api'
|
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) : [],
|
services: Array.isArray(body.services) ? body.services.filter(Boolean) : [],
|
||||||
profils: Array.isArray(body.profils) ? body.profils.filter(Boolean) : [],
|
profils: Array.isArray(body.profils) ? body.profils.filter(Boolean) : [],
|
||||||
participation: body.participation || 'default',
|
participation: body.participation || 'default',
|
||||||
creatorId: userId,
|
creatorId: creatorId,
|
||||||
logo: body.logo || null,
|
logo: body.logo || null,
|
||||||
leantimeProjectId: body.leantimeProjectId || null,
|
leantimeProjectId: body.leantimeProjectId || null,
|
||||||
outlineCollectionId: body.documentationCollectionId || null,
|
outlineCollectionId: body.documentationCollectionId || null,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user