W n8n
This commit is contained in:
parent
50a710ba55
commit
5fd673cdfb
@ -205,30 +205,29 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
// Prepare the data for n8n
|
// Prepare the data for n8n
|
||||||
const n8nData = {
|
const n8nData = {
|
||||||
...body,
|
name: body.name,
|
||||||
|
oddScope: Array.isArray(body.oddScope) ? body.oddScope : [body.oddScope],
|
||||||
|
niveau: body.niveau || 'default',
|
||||||
|
intention: body.intention?.trim() || '',
|
||||||
|
missionType: body.missionType || 'default',
|
||||||
|
donneurDOrdre: body.donneurDOrdre || 'default',
|
||||||
|
projection: body.projection || 'default',
|
||||||
|
services: Array.isArray(body.services) ? body.services : [],
|
||||||
|
participation: body.participation || 'default',
|
||||||
|
profils: Array.isArray(body.profils) ? body.profils : [],
|
||||||
|
guardians: body.guardians || {},
|
||||||
|
volunteers: Array.isArray(body.volunteers) ? body.volunteers : [],
|
||||||
creatorId: userId,
|
creatorId: userId,
|
||||||
requestId,
|
config: {
|
||||||
// Ensure guardians and volunteers are properly formatted
|
N8N_API_KEY: process.env.N8N_API_KEY,
|
||||||
guardians: body.guardians ? Object.entries(body.guardians).reduce((acc, [role, userId]) => {
|
MISSION_API_URL: process.env.NEXT_PUBLIC_API_URL || 'https://api.slm-lab.net/api'
|
||||||
if (userId) {
|
|
||||||
acc[role] = userId;
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
}, {} as Record<string, string>) : {},
|
|
||||||
volunteers: Array.isArray(body.volunteers) ? body.volunteers.filter(Boolean) : [],
|
|
||||||
// Add metadata for n8n workflow
|
|
||||||
metadata: {
|
|
||||||
hasGuardians: Boolean(body.guardians && Object.keys(body.guardians).length > 0),
|
|
||||||
volunteersCount: Array.isArray(body.volunteers) ? body.volunteers.length : 0,
|
|
||||||
hasConfig: true,
|
|
||||||
configKeys: ['N8N_API_KEY', 'MISSION_API_URL']
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Sending data to n8n workflow:', {
|
console.log('Sending data to n8n workflow:', {
|
||||||
...n8nData,
|
...n8nData,
|
||||||
password: undefined // Don't log sensitive data
|
config: { ...n8nData.config, N8N_API_KEY: '[REDACTED]' } // Don't log sensitive data
|
||||||
});
|
});
|
||||||
|
|
||||||
const workflowResult = await n8nService.triggerMissionCreation(n8nData);
|
const workflowResult = await n8nService.triggerMissionCreation(n8nData);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user