This commit is contained in:
alma 2025-05-22 19:09:11 +02:00
parent 6877062826
commit bb73f26292
2 changed files with 42 additions and 51 deletions

View File

@ -223,7 +223,7 @@ export async function POST(request: Request) {
const mission = await prisma.mission.create({
data: {
name,
oddScope: oddScope || 'default',
oddScope: oddScope || ['default'],
niveau,
intention,
missionType,
@ -233,12 +233,14 @@ export async function POST(request: Request) {
profils: Array.isArray(profils) ? profils.filter(Boolean) : [],
participation: participation || 'default',
creatorId: userId,
logo: results.logoUrl, // Use the logo URL from n8n
leantimeProjectId: results.leantimeProjectId?.toString(),
outlineCollectionId: results.outlineCollectionId?.toString(),
rocketChatChannelId: results.rocketChatChannelId?.toString(),
giteaRepositoryUrl: results.giteaRepositoryUrl?.toString()
}
logo: results.logoUrl || null,
// Store integration IDs directly in the mission record
leantimeProjectId: results.leantimeProjectId?.toString() || null,
outlineCollectionId: results.outlineCollectionId?.toString() || null,
rocketChatChannelId: results.rocketChatChannelId?.toString() || null,
giteaRepositoryUrl: results.giteaRepositoryUrl?.toString() || null,
penpotProjectId: results.penpotProjectId?.toString() || null
} as Prisma.MissionUncheckedCreateInput
});
console.log('Created mission:', JSON.stringify(mission, null, 2));

View File

@ -18,68 +18,56 @@ export class N8nService {
async triggerMissionCreation(data: any): Promise<any> {
try {
// Log the incoming data
console.log('Incoming data to n8n service:', {
hasMissionId: !!data.missionId,
hasName: !!data.name,
hasCreatorId: !!data.creatorId,
oddScope: data.oddScope,
niveau: data.niveau,
intention: data.intention,
missionType: data.missionType,
donneurDOrdre: data.donneurDOrdre,
projection: data.projection,
services: data.services,
participation: data.participation,
profils: data.profils
});
// Add API key and default values to the data
const dataWithDefaults = {
...data,
oddScope: data.oddScope || 'default',
// Clean and validate the data
const cleanData = {
name: data.name,
oddScope: Array.isArray(data.oddScope) ? data.oddScope : [data.oddScope],
niveau: data.niveau || 'default',
intention: data.intention?.trim() || '',
missionType: data.missionType || 'default',
donneurDOrdre: data.donneurDOrdre || 'default',
projection: data.projection || 'default',
services: Array.isArray(data.services) ? data.services : [],
participation: data.participation || 'default',
profils: Array.isArray(data.profils) ? data.profils : [],
guardians: data.guardians || {},
volunteers: Array.isArray(data.volunteers) ? data.volunteers : [],
creatorId: data.creatorId,
config: {
...data.config,
N8N_API_KEY: this.apiKey,
MISSION_API_URL: process.env.NEXT_PUBLIC_API_URL || 'https://api.slm-lab.net/api'
}
};
// Log the exact data structure being sent
console.log('Data structure being sent to n8n:', {
missionId: dataWithDefaults.missionId,
name: dataWithDefaults.name,
creatorId: dataWithDefaults.creatorId,
hasConfig: !!dataWithDefaults.config,
configKeys: dataWithDefaults.config ? Object.keys(dataWithDefaults.config) : [],
apiKeyPresent: !!dataWithDefaults.config?.N8N_API_KEY,
apiUrlPresent: !!dataWithDefaults.config?.MISSION_API_URL,
fullData: JSON.stringify(dataWithDefaults, null, 2)
// Log the cleaned data
console.log('Sending cleaned data to n8n:', {
name: cleanData.name,
creatorId: cleanData.creatorId,
oddScope: cleanData.oddScope,
niveau: cleanData.niveau,
intention: cleanData.intention?.substring(0, 100) + '...', // Log first 100 chars
missionType: cleanData.missionType,
donneurDOrdre: cleanData.donneurDOrdre,
projection: cleanData.projection,
services: cleanData.services,
participation: cleanData.participation,
profils: cleanData.profils,
hasGuardians: !!cleanData.guardians,
volunteersCount: cleanData.volunteers.length,
hasConfig: !!cleanData.config,
configKeys: cleanData.config ? Object.keys(cleanData.config) : []
});
console.log('Using webhook URL:', this.webhookUrl);
console.log('API key present:', !!this.apiKey);
// Log the full request details
const requestDetails = {
url: this.webhookUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': this.apiKey
},
body: dataWithDefaults
};
console.log('Full request details:', JSON.stringify(requestDetails, null, 2));
const response = await fetch(this.webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': this.apiKey
},
body: JSON.stringify(dataWithDefaults),
body: JSON.stringify(cleanData),
});
console.log('Webhook response status:', response.status);
@ -114,6 +102,7 @@ export class N8nService {
return {
success: true,
results: {
logoUrl: null,
leantimeProjectId: null,
outlineCollectionId: null,
rocketChatChannelId: null,