missions api2
This commit is contained in:
parent
f0fd085dc8
commit
f53684eb1c
@ -38,23 +38,59 @@ export class LeantimeService {
|
||||
throw new Error(`Leantime client not found for mission type ${mission.niveau}`);
|
||||
}
|
||||
|
||||
// Generate dates for the project (today and one year from now)
|
||||
const today = new Date();
|
||||
const endDate = new Date();
|
||||
endDate.setFullYear(today.getFullYear() + 1);
|
||||
|
||||
const formattedStartDate = today.toISOString().split('T')[0];
|
||||
const formattedEndDate = endDate.toISOString().split('T')[0];
|
||||
|
||||
console.log(`Creating project with dates: start=${formattedStartDate}, end=${formattedEndDate}`);
|
||||
|
||||
// Create the project - Follow the exact same pattern from user creation which works
|
||||
// This pattern matches the Leantime PHP backend expectations
|
||||
const payload = {
|
||||
method: 'leantime.rpc.Projects.Projects.addProject',
|
||||
jsonrpc: '2.0',
|
||||
id: 1,
|
||||
params: {
|
||||
// Use the same pattern of indexed properties + named properties that works in createLeantimeUser
|
||||
values: {
|
||||
'0': 0, // project ID will be set by Leantime
|
||||
'1': mission.name, // name
|
||||
'2': mission.intention || '', // details
|
||||
'3': clientId, // clientId
|
||||
'4': 'project', // type
|
||||
'5': formattedStartDate, // start
|
||||
'6': formattedEndDate, // end
|
||||
'7': 'open', // status
|
||||
'8': 0, // hourBudget
|
||||
'9': 0, // dollarBudget
|
||||
'10': 'restricted', // psettings
|
||||
|
||||
// Also include named keys for robustness
|
||||
clientId: clientId,
|
||||
name: mission.name,
|
||||
details: mission.intention || '',
|
||||
type: 'project',
|
||||
start: formattedStartDate,
|
||||
end: formattedEndDate,
|
||||
status: 'open',
|
||||
hourBudget: 0,
|
||||
dollarBudget: 0,
|
||||
psettings: 'restricted'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Log the full payload
|
||||
console.log('Project creation payload:', JSON.stringify(payload, null, 2));
|
||||
|
||||
// Create the project
|
||||
const response = await axios.post(
|
||||
this.getApiEndpoint(),
|
||||
{
|
||||
method: 'leantime.rpc.Projects.Projects.addProject',
|
||||
jsonrpc: '2.0',
|
||||
id: 1,
|
||||
params: {
|
||||
values: {
|
||||
name: mission.name,
|
||||
details: mission.intention || '',
|
||||
clientId: clientId,
|
||||
type: 'project',
|
||||
psettings: 'restricted',
|
||||
}
|
||||
}
|
||||
},
|
||||
payload,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -63,6 +99,10 @@ export class LeantimeService {
|
||||
}
|
||||
);
|
||||
|
||||
// Log the response
|
||||
console.log('Leantime response status:', response.status);
|
||||
console.log('Leantime response:', JSON.stringify(response.data, null, 2));
|
||||
|
||||
if (!response.data || !response.data.result) {
|
||||
throw new Error(`Failed to create Leantime project: ${JSON.stringify(response.data)}`);
|
||||
}
|
||||
@ -82,6 +122,13 @@ export class LeantimeService {
|
||||
|
||||
return projectId;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error) && error.response) {
|
||||
console.error('Axios Error Details:', {
|
||||
status: error.response.status,
|
||||
data: error.response.data,
|
||||
headers: error.response.headers
|
||||
});
|
||||
}
|
||||
console.error('Error creating Leantime project:', error);
|
||||
throw new Error(`Leantime integration failed: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user