arreglar una cosita
This commit is contained in:
parent
6e2bd5d7fb
commit
9a73b23f85
|
|
@ -27,8 +27,19 @@ export async function GET(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construir URL completa
|
// Construir URL completa (soporta query params en el endpoint + request)
|
||||||
const url = `${apiUrl}/${endpoint}?DOLAPIKEY=${apiKey}`;
|
const [baseEndpoint, queryString] = endpoint.split('?');
|
||||||
|
let url = `${apiUrl}/${baseEndpoint}?DOLAPIKEY=${apiKey}`;
|
||||||
|
if (queryString) {
|
||||||
|
url += `&${queryString}`;
|
||||||
|
}
|
||||||
|
// Reenviar query params de la request original (para client-side)
|
||||||
|
const searchParams = request.nextUrl.searchParams;
|
||||||
|
searchParams.forEach((value, key) => {
|
||||||
|
if (key !== 'DOLAPIKEY') {
|
||||||
|
url += `&${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Realizar la petición a Dolibarr
|
// Realizar la petición a Dolibarr
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
|
|
@ -86,7 +97,11 @@ export async function POST(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${apiUrl}/${endpoint}?DOLAPIKEY=${apiKey}`;
|
const [baseEndpoint, queryString] = endpoint.split('?');
|
||||||
|
let url = `${apiUrl}/${baseEndpoint}?DOLAPIKEY=${apiKey}`;
|
||||||
|
if (queryString) {
|
||||||
|
url += `&${queryString}`;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
@ -158,7 +173,11 @@ export async function PUT(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${apiUrl}/${endpoint}?DOLAPIKEY=${apiKey}`;
|
const [baseEndpoint, queryString] = endpoint.split('?');
|
||||||
|
let url = `${apiUrl}/${baseEndpoint}?DOLAPIKEY=${apiKey}`;
|
||||||
|
if (queryString) {
|
||||||
|
url += `&${queryString}`;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
|
@ -227,7 +246,11 @@ export async function DELETE(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${apiUrl}/${endpoint}?DOLAPIKEY=${apiKey}`;
|
const [baseEndpoint, queryString] = endpoint.split('?');
|
||||||
|
let url = `${apiUrl}/${baseEndpoint}?DOLAPIKEY=${apiKey}`;
|
||||||
|
if (queryString) {
|
||||||
|
url += `&${queryString}`;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,11 @@ async function dolibarrDirectFetch(endpoint: string, options: RequestInit = {})
|
||||||
throw new Error('Dolibarr configuration missing (DOLIBARR_API_URL or DOLIBARR_API_KEY)');
|
throw new Error('Dolibarr configuration missing (DOLIBARR_API_URL or DOLIBARR_API_KEY)');
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${apiUrl}/${endpoint}?DOLAPIKEY=${apiKey}`;
|
const [baseEndpoint, queryString] = endpoint.split('?');
|
||||||
|
let url = `${apiUrl}/${baseEndpoint}?DOLAPIKEY=${apiKey}`;
|
||||||
|
if (queryString) {
|
||||||
|
url += `&${queryString}`;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
...options,
|
...options,
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,14 @@ import {
|
||||||
*
|
*
|
||||||
* Nota: El endpoint /projects/{id}/tasks de Dolibarr no devuelve tareas correctamente,
|
* Nota: El endpoint /projects/{id}/tasks de Dolibarr no devuelve tareas correctamente,
|
||||||
* por lo que obtenemos todas las tareas y filtramos por fk_project en el cliente.
|
* por lo que obtenemos todas las tareas y filtramos por fk_project en el cliente.
|
||||||
|
* Se usa limit=10000 para evitar problemas de paginación por defecto (100).
|
||||||
*/
|
*/
|
||||||
export async function getTasksByProjectId(projectId: number): Promise<Task[]> {
|
export async function getTasksByProjectId(projectId: number): Promise<Task[]> {
|
||||||
try {
|
try {
|
||||||
// Obtener todas las tareas (Dolibarr no filtra bien por proyecto)
|
// Usar limit alto + sortfield para obtener todas las tareas y evitar paginación
|
||||||
const dolibarrTasks: DolibarrTask[] = await dolibarrFetch('tasks');
|
const dolibarrTasks: DolibarrTask[] = await dolibarrFetch(
|
||||||
|
`tasks?limit=10000&sortfield=t.rowid&sortorder=ASC`
|
||||||
|
);
|
||||||
|
|
||||||
// Si no hay tareas, devolver array vacío
|
// Si no hay tareas, devolver array vacío
|
||||||
if (!dolibarrTasks || !Array.isArray(dolibarrTasks)) {
|
if (!dolibarrTasks || !Array.isArray(dolibarrTasks)) {
|
||||||
|
|
@ -47,7 +50,9 @@ export async function getTasksByProjectId(projectId: number): Promise<Task[]> {
|
||||||
*/
|
*/
|
||||||
export async function getAllTasks(): Promise<Task[]> {
|
export async function getAllTasks(): Promise<Task[]> {
|
||||||
try {
|
try {
|
||||||
const dolibarrTasks: DolibarrTask[] = await dolibarrFetch('tasks');
|
const dolibarrTasks: DolibarrTask[] = await dolibarrFetch(
|
||||||
|
'tasks?limit=10000&sortfield=t.rowid&sortorder=ASC'
|
||||||
|
);
|
||||||
|
|
||||||
if (!dolibarrTasks || !Array.isArray(dolibarrTasks)) {
|
if (!dolibarrTasks || !Array.isArray(dolibarrTasks)) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
https://canva.link/rvvkr8loc8gx8v1
|
https://canva.link/####rvvkr8loc8gx8v1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue