missions api2

This commit is contained in:
alma 2025-05-06 16:03:33 +02:00
parent df1cc29b57
commit 9946dd8f48

View File

@ -103,19 +103,22 @@ export class LeantimeService {
// Fall back to addProject if createProject fails // Fall back to addProject if createProject fails
console.log('createProject failed, trying addProject...'); console.log('createProject failed, trying addProject...');
// Based on the error message, Leantime expects a nested 'values' parameter
const payload = { const payload = {
method: 'leantime.rpc.Projects.addProject', method: 'leantime.rpc.Projects.Projects.addProject',
jsonrpc: '2.0', jsonrpc: '2.0',
id: 1, id: 1,
params: { params: {
name: mission.name, values: {
clientId: clientId, name: mission.name,
details: mission.intention || '', clientId: clientId,
type: 'project', details: mission.intention || '',
start: formattedStartDate, type: 'project',
end: formattedEndDate, start: formattedStartDate,
status: 'open', end: formattedEndDate,
psettings: 'restricted' status: 'open',
psettings: 'restricted'
}
} }
}; };
@ -258,11 +261,11 @@ export class LeantimeService {
try { try {
console.log(`Assigning user ${userId} to project ${projectId} with role ${role}`); console.log(`Assigning user ${userId} to project ${projectId} with role ${role}`);
// Try with Projects.addUser first // Try with Projects.Projects.addUser first
const response = await axios.post( const response = await axios.post(
this.getApiEndpoint(), this.getApiEndpoint(),
{ {
method: 'leantime.rpc.Projects.addUser', method: 'leantime.rpc.Projects.Projects.addUser',
jsonrpc: '2.0', jsonrpc: '2.0',
id: 1, id: 1,
params: { params: {
@ -308,7 +311,35 @@ export class LeantimeService {
); );
if (!altResponse.data || !altResponse.data.result) { if (!altResponse.data || !altResponse.data.result) {
throw new Error(`Failed to assign user to project with both methods: ${JSON.stringify(altResponse.data)}`); // Try one more time with the Projects.assignUserToProject format
console.log('Second method failed, trying Projects.assignUserToProject...');
const thirdResponse = await axios.post(
this.getApiEndpoint(),
{
method: 'leantime.rpc.Projects.assignUserToProject',
jsonrpc: '2.0',
id: 1,
params: {
projectId: projectId,
userId: userId,
role: role
}
},
{
headers: {
'Content-Type': 'application/json',
'X-API-Key': this.apiToken
}
}
);
if (!thirdResponse.data || !thirdResponse.data.result) {
throw new Error(`Failed to assign user to project with all methods: ${JSON.stringify(thirdResponse.data)}`);
}
console.log(`Assigned user ${userId} to project ${projectId} with role ${role} using third method`);
return;
} }
console.log(`Assigned user ${userId} to project ${projectId} with role ${role} using alternative method`); console.log(`Assigned user ${userId} to project ${projectId} with role ${role} using alternative method`);