n8n int cleaning

This commit is contained in:
alma 2025-05-18 09:13:12 +02:00
parent 6e29074f5c
commit 88b35ad698
2 changed files with 19 additions and 66 deletions

View File

@ -15,6 +15,17 @@ export class N8nService {
console.log('Triggering n8n workflow with data:', JSON.stringify(data, null, 2));
console.log('Using webhook URL:', this.webhookUrl);
// Log the full request details
const requestDetails = {
url: this.webhookUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: data
};
console.log('Full request details:', JSON.stringify(requestDetails, null, 2));
const response = await fetch(this.webhookUrl, {
method: 'POST',
headers: {
@ -35,69 +46,16 @@ export class N8nService {
const responseText = await response.text();
console.log('Raw response from n8n:', responseText);
// Handle 'allEntries' response
if (responseText === 'allEntries') {
console.log('Received allEntries response, workflow triggered successfully');
return {
success: true,
results: {
leantimeProjectId: null,
outlineCollectionId: null,
rocketChatChannelId: null,
giteaRepositoryUrl: null
}
};
}
// Try to parse the response as JSON
try {
// Try to parse as JSON
const result = JSON.parse(responseText);
console.log('Parsed JSON response:', JSON.stringify(result, null, 2));
// Handle lastNodeJson format
if (result.lastNodeJson) {
try {
const parsedResults = JSON.parse(result.lastNodeJson);
return {
success: true,
results: {
leantimeProjectId: parsedResults.leantimeProjectId?.toString() || null,
outlineCollectionId: parsedResults.outlineCollectionId?.toString() || null,
rocketChatChannelId: parsedResults.rocketChatChannelId?.toString() || null,
giteaRepositoryUrl: parsedResults.giteaRepositoryUrl || null
}
};
} catch (parseError) {
console.error('Error parsing lastNodeJson:', parseError);
return {
success: false,
error: 'Failed to parse n8n response',
results: {
leantimeProjectId: null,
outlineCollectionId: null,
rocketChatChannelId: null,
giteaRepositoryUrl: null
}
};
}
}
// Handle regular JSON response
const integrationResults = result.results || result;
console.log('Integration results:', JSON.stringify(integrationResults, null, 2));
console.log('Parsed workflow result:', JSON.stringify(result, null, 2));
return {
success: true,
results: {
leantimeProjectId: integrationResults.leantimeProjectId?.toString() || null,
outlineCollectionId: integrationResults.outlineCollectionId?.toString() || null,
rocketChatChannelId: integrationResults.rocketChatChannelId?.toString() || null,
giteaRepositoryUrl: integrationResults.giteaRepositoryUrl || null
}
results: result
};
} catch (parseError) {
console.error('Error parsing response:', parseError);
// If parsing fails, return a default success response
console.log('Response is not JSON, treating as workflow trigger confirmation');
return {
success: true,
results: {
@ -112,13 +70,7 @@ export class N8nService {
console.error('Error triggering n8n workflow:', error);
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
results: {
leantimeProjectId: null,
outlineCollectionId: null,
rocketChatChannelId: null,
giteaRepositoryUrl: null
}
error: error instanceof Error ? error.message : 'Unknown error'
};
}
}

File diff suppressed because one or more lines are too long