W n8n
This commit is contained in:
parent
67f495872f
commit
543a964235
File diff suppressed because one or more lines are too long
@ -20,11 +20,11 @@ interface MissionCreateInput {
|
|||||||
guardians?: Record<string, string>;
|
guardians?: Record<string, string>;
|
||||||
volunteers?: string[];
|
volunteers?: string[];
|
||||||
logo?: string | null;
|
logo?: string | null;
|
||||||
leantimeProjectId?: string;
|
leantimeProjectId?: string | null;
|
||||||
documentationCollectionId?: string;
|
outlineCollectionId?: string | null;
|
||||||
rocketchatChannelId?: string;
|
rocketChatChannelId?: string | null;
|
||||||
gitRepoUrl?: string;
|
giteaRepositoryUrl?: string | null;
|
||||||
penpotProjectId?: string;
|
penpotProjectId?: string | null;
|
||||||
creatorId?: string;
|
creatorId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +34,26 @@ interface MissionUserInput {
|
|||||||
missionId: string;
|
missionId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface MissionResponse {
|
||||||
|
name: string;
|
||||||
|
oddScope: string[];
|
||||||
|
niveau: string;
|
||||||
|
intention: string;
|
||||||
|
missionType: string;
|
||||||
|
donneurDOrdre: string;
|
||||||
|
projection: string;
|
||||||
|
services: string[];
|
||||||
|
profils: string[];
|
||||||
|
participation: string;
|
||||||
|
creatorId: string;
|
||||||
|
logo: string | null;
|
||||||
|
leantimeProjectId: string | null;
|
||||||
|
outlineCollectionId: string | null;
|
||||||
|
rocketChatChannelId: string | null;
|
||||||
|
giteaRepositoryUrl: string | null;
|
||||||
|
penpotProjectId: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to check authentication
|
// Helper function to check authentication
|
||||||
async function checkAuth(request: Request) {
|
async function checkAuth(request: Request) {
|
||||||
const apiKey = request.headers.get('x-api-key');
|
const apiKey = request.headers.get('x-api-key');
|
||||||
@ -171,9 +191,9 @@ export async function POST(request: Request) {
|
|||||||
where: { id: existingMission.id },
|
where: { id: existingMission.id },
|
||||||
data: {
|
data: {
|
||||||
leantimeProjectId: body.leantimeProjectId ? String(body.leantimeProjectId) : null,
|
leantimeProjectId: body.leantimeProjectId ? String(body.leantimeProjectId) : null,
|
||||||
outlineCollectionId: body.documentationCollectionId || null,
|
outlineCollectionId: body.outlineCollectionId || null,
|
||||||
rocketChatChannelId: body.rocketchatChannelId || null,
|
rocketChatChannelId: body.rocketChatChannelId || null,
|
||||||
giteaRepositoryUrl: body.gitRepoUrl || null,
|
giteaRepositoryUrl: body.giteaRepositoryUrl || null,
|
||||||
penpotProjectId: body.penpotProjectId || null
|
penpotProjectId: body.penpotProjectId || null
|
||||||
} as Prisma.MissionUpdateInput
|
} as Prisma.MissionUpdateInput
|
||||||
});
|
});
|
||||||
@ -318,9 +338,9 @@ export async function POST(request: Request) {
|
|||||||
creatorId: creatorId,
|
creatorId: creatorId,
|
||||||
logo: body.logo || null,
|
logo: body.logo || null,
|
||||||
leantimeProjectId: body.leantimeProjectId ? String(body.leantimeProjectId) : null,
|
leantimeProjectId: body.leantimeProjectId ? String(body.leantimeProjectId) : null,
|
||||||
outlineCollectionId: body.documentationCollectionId || null,
|
outlineCollectionId: body.outlineCollectionId || null,
|
||||||
rocketChatChannelId: body.rocketchatChannelId || null,
|
rocketChatChannelId: body.rocketChatChannelId || null,
|
||||||
giteaRepositoryUrl: body.gitRepoUrl || null,
|
giteaRepositoryUrl: body.giteaRepositoryUrl || null,
|
||||||
penpotProjectId: body.penpotProjectId || null
|
penpotProjectId: body.penpotProjectId || null
|
||||||
} as Prisma.MissionUncheckedCreateInput
|
} as Prisma.MissionUncheckedCreateInput
|
||||||
});
|
});
|
||||||
@ -362,25 +382,58 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format response to match workflow output
|
||||||
|
const missionResponse: MissionResponse = {
|
||||||
|
name: mission.name,
|
||||||
|
oddScope: mission.oddScope,
|
||||||
|
niveau: mission.niveau,
|
||||||
|
intention: mission.intention,
|
||||||
|
missionType: mission.missionType,
|
||||||
|
donneurDOrdre: mission.donneurDOrdre,
|
||||||
|
projection: mission.projection,
|
||||||
|
services: mission.services,
|
||||||
|
profils: mission.profils,
|
||||||
|
participation: mission.participation || 'default',
|
||||||
|
creatorId: mission.creatorId,
|
||||||
|
logo: mission.logo,
|
||||||
|
leantimeProjectId: (mission as any).leantimeProjectId,
|
||||||
|
outlineCollectionId: (mission as any).outlineCollectionId,
|
||||||
|
rocketChatChannelId: (mission as any).rocketChatChannelId,
|
||||||
|
giteaRepositoryUrl: (mission as any).giteaRepositoryUrl,
|
||||||
|
penpotProjectId: (mission as any).penpotProjectId
|
||||||
|
};
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
status: 'success',
|
||||||
message: 'Mission created successfully',
|
message: 'Mission created successfully',
|
||||||
mission
|
mission: missionResponse,
|
||||||
|
integrationStatus: {
|
||||||
|
leantimeProject: !!missionResponse.leantimeProjectId,
|
||||||
|
outlineCollection: !!missionResponse.outlineCollectionId,
|
||||||
|
rocketChatChannel: !!missionResponse.rocketChatChannelId,
|
||||||
|
giteaRepository: !!missionResponse.giteaRepositoryUrl
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating mission:', error);
|
console.error('Error creating mission:', error);
|
||||||
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
if (error instanceof Prisma.PrismaClientKnownRequestError) {
|
||||||
if (error.code === 'P2003') {
|
if (error.code === 'P2003') {
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
status: 'error',
|
||||||
error: 'Invalid reference',
|
error: 'Invalid reference',
|
||||||
details: 'One or more referenced users do not exist',
|
message: 'One or more referenced users do not exist',
|
||||||
code: 'INVALID_REFERENCE'
|
code: 'INVALID_REFERENCE'
|
||||||
}, { status: 400 });
|
}, { status: 400 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
|
success: false,
|
||||||
|
status: 'error',
|
||||||
error: 'Failed to create mission',
|
error: 'Failed to create mission',
|
||||||
details: error instanceof Error ? error.message : String(error)
|
message: error instanceof Error ? error.message : String(error)
|
||||||
},
|
},
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user