n8n int cleaning
This commit is contained in:
parent
2d25992870
commit
f4cdad3589
@ -152,11 +152,12 @@ export async function POST(request: Request) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
console.error('Unauthorized access attempt - no session or user');
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
console.log('Received mission creation request:', body);
|
||||
console.log('Received mission creation request:', JSON.stringify(body, null, 2));
|
||||
|
||||
const { name, oddScope, niveau, intention, missionType, donneurDOrdre, projection, services, participation, profils, guardians, volunteers } = body;
|
||||
|
||||
@ -194,6 +195,7 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ error: 'A mission with this name already exists' }, { status: 400 });
|
||||
}
|
||||
|
||||
console.log('Creating mission in database...');
|
||||
// Create the mission
|
||||
const mission = await prisma.mission.create({
|
||||
data: {
|
||||
@ -204,17 +206,18 @@ export async function POST(request: Request) {
|
||||
missionType,
|
||||
donneurDOrdre,
|
||||
projection,
|
||||
services,
|
||||
profils,
|
||||
services: Array.isArray(services) ? services.filter(Boolean) : [],
|
||||
profils: Array.isArray(profils) ? profils.filter(Boolean) : [],
|
||||
participation,
|
||||
creatorId: session.user.id
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Created mission:', mission);
|
||||
console.log('Created mission:', JSON.stringify(mission, null, 2));
|
||||
|
||||
// Add guardians and volunteers
|
||||
if (guardians || volunteers) {
|
||||
console.log('Adding guardians and volunteers...');
|
||||
const missionUsers: MissionUserInput[] = [];
|
||||
|
||||
// Add guardians
|
||||
@ -244,6 +247,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
if (missionUsers.length > 0) {
|
||||
console.log('Creating mission users:', JSON.stringify(missionUsers, null, 2));
|
||||
await prisma.missionUser.createMany({
|
||||
data: missionUsers
|
||||
});
|
||||
@ -252,12 +256,12 @@ export async function POST(request: Request) {
|
||||
|
||||
// Trigger n8n workflow
|
||||
const n8nService = new N8nService();
|
||||
console.log('About to trigger n8n workflow with data:', {
|
||||
console.log('About to trigger n8n workflow with data:', JSON.stringify({
|
||||
missionId: mission.id,
|
||||
name: mission.name,
|
||||
creatorId: mission.creatorId,
|
||||
fullData: body
|
||||
});
|
||||
}, null, 2));
|
||||
|
||||
try {
|
||||
const workflowResult = await n8nService.triggerMissionCreation({
|
||||
@ -266,7 +270,7 @@ export async function POST(request: Request) {
|
||||
creatorId: mission.creatorId
|
||||
});
|
||||
|
||||
console.log('Received workflow result:', workflowResult);
|
||||
console.log('Received workflow result:', JSON.stringify(workflowResult, null, 2));
|
||||
|
||||
if (!workflowResult.success) {
|
||||
console.error('N8n workflow failed:', workflowResult.error);
|
||||
@ -276,7 +280,7 @@ export async function POST(request: Request) {
|
||||
|
||||
// Process workflow results
|
||||
const results = workflowResult.results || {};
|
||||
console.log('Processing workflow results:', results);
|
||||
console.log('Processing workflow results:', JSON.stringify(results, null, 2));
|
||||
|
||||
// Update mission with integration data
|
||||
const integrationData = {
|
||||
@ -286,7 +290,7 @@ export async function POST(request: Request) {
|
||||
giteaRepositoryUrl: results.giteaRepositoryUrl?.toString()
|
||||
} as Prisma.MissionUpdateInput;
|
||||
|
||||
console.log('Updating mission with integration data:', integrationData);
|
||||
console.log('Updating mission with integration data:', JSON.stringify(integrationData, null, 2));
|
||||
|
||||
const updatedMission = await prisma.mission.update({
|
||||
where: { id: mission.id },
|
||||
|
||||
@ -379,7 +379,7 @@ export function MissionsAdminPanel() {
|
||||
// Handle mission submission
|
||||
const handleSubmitMission = async () => {
|
||||
console.log('Starting mission submission...');
|
||||
console.log('Current mission data:', missionData);
|
||||
console.log('Current mission data:', JSON.stringify(missionData, null, 2));
|
||||
console.log('Guardians:', {
|
||||
gardienDuTemps,
|
||||
gardienDeLaParole,
|
||||
@ -408,7 +408,7 @@ export function MissionsAdminPanel() {
|
||||
volunteers: volontaires
|
||||
};
|
||||
|
||||
console.log('Submitting mission data:', formattedData);
|
||||
console.log('Submitting mission data:', JSON.stringify(formattedData, null, 2));
|
||||
|
||||
const response = await fetch('/api/missions', {
|
||||
method: 'POST',
|
||||
@ -420,9 +420,10 @@ export function MissionsAdminPanel() {
|
||||
|
||||
console.log('Response status:', response.status);
|
||||
const data = await response.json();
|
||||
console.log('Response data:', data);
|
||||
console.log('Response data:', JSON.stringify(data, null, 2));
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Error response:', data);
|
||||
throw new Error(data.error || 'Failed to create mission');
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user