modification for list
This commit is contained in:
@@ -312,19 +312,39 @@ const dataconnectEntityConfig = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Sector:{
|
Sector:{
|
||||||
|
list: 'listSector',
|
||||||
|
get: 'getSectorById',
|
||||||
|
create: 'createSector',
|
||||||
|
update: 'updateSector',
|
||||||
|
delete: 'deleteSector',
|
||||||
|
filter: 'filterSector'
|
||||||
},
|
},
|
||||||
|
|
||||||
Partner:{
|
Partner:{
|
||||||
|
list: 'listPartner',
|
||||||
|
get: 'getPartnerById',
|
||||||
|
create: 'createPartner',
|
||||||
|
update: 'updatePartner',
|
||||||
|
delete: 'deletePartner',
|
||||||
|
filter: 'filterPartner'
|
||||||
},
|
},
|
||||||
|
|
||||||
Order:{
|
Order:{
|
||||||
|
list: 'listOrder',
|
||||||
|
get: 'getOrderById',
|
||||||
|
create: 'createOrder',
|
||||||
|
update: 'updateOrder',
|
||||||
|
delete: 'deleteOrder',
|
||||||
|
filter: 'filterOrder'
|
||||||
},
|
},
|
||||||
|
|
||||||
Shift:{
|
Shift:{
|
||||||
|
list: 'listShift',
|
||||||
|
get: 'getShiftById',
|
||||||
|
create: 'createShift',
|
||||||
|
update: 'updateShift',
|
||||||
|
delete: 'deleteShift',
|
||||||
|
filter: 'filterShift'
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -404,7 +424,7 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
|
|||||||
// list
|
// list
|
||||||
...(ops.list && {
|
...(ops.list && {
|
||||||
list: async (...args) => {
|
list: async (...args) => {
|
||||||
const fn = dcSdk[ops.list];
|
/*const fn = dcSdk[ops.list];
|
||||||
if (typeof fn !== 'function') {
|
if (typeof fn !== 'function') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Data Connect operation "${ops.list}" not found for entity "${entityName}".`
|
`Data Connect operation "${ops.list}" not found for entity "${entityName}".`
|
||||||
@@ -445,10 +465,8 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// COMMENT FIX: variables que realmente se mandan a DataConnect
|
|
||||||
let variables = baseVariables;
|
let variables = baseVariables;
|
||||||
|
|
||||||
// COMMENT FIX: caso especial para Team, que SÍ tiene orderBy/limit en el query
|
|
||||||
if (entityName === "Team") {
|
if (entityName === "Team") {
|
||||||
variables = variables || {};
|
variables = variables || {};
|
||||||
if (sort) {
|
if (sort) {
|
||||||
@@ -463,7 +481,7 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
|
|||||||
const res = await fn(dataConnect, variables);
|
const res = await fn(dataConnect, variables);
|
||||||
let items = normalizeResultToArray(res);
|
let items = normalizeResultToArray(res);
|
||||||
|
|
||||||
// COMMENT FIX: para entidades que NO tienen orderBy/limit en el query,
|
// para entidades que NO tienen orderBy/limit en el query,
|
||||||
// aplicamos sort/limit en el front como fallback.
|
// aplicamos sort/limit en el front como fallback.
|
||||||
if (entityName !== "Team" && sort) {
|
if (entityName !== "Team" && sort) {
|
||||||
const desc = sort.startsWith("-");
|
const desc = sort.startsWith("-");
|
||||||
@@ -494,7 +512,85 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
|
|||||||
}
|
}
|
||||||
//console.log(items)
|
//console.log(items)
|
||||||
//return items;
|
//return items;
|
||||||
|
*/
|
||||||
|
const fn = dcSdk[ops.list];
|
||||||
|
if (typeof fn !== 'function') {
|
||||||
|
throw new Error(
|
||||||
|
`Data Connect operation "${ops.list}" not found for entity "${entityName}".`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// --- Lógica de parseo de argumentos (se mantiene para compatibilidad) ---
|
||||||
|
let sort;
|
||||||
|
let limit;
|
||||||
|
let baseVariables;
|
||||||
|
|
||||||
|
if (args.length === 1) {
|
||||||
|
const [a0] = args;
|
||||||
|
if (typeof a0 === "string") sort = a0;
|
||||||
|
else if (a0 && typeof a0 === "object") baseVariables = a0;
|
||||||
|
} else if (args.length === 2) {
|
||||||
|
const [a0, a1] = args;
|
||||||
|
if (typeof a0 === "string" && typeof a1 === "number") {
|
||||||
|
sort = a0;
|
||||||
|
limit = a1;
|
||||||
|
} else if (a0 && typeof a0 === "object") {
|
||||||
|
baseVariables = a0;
|
||||||
|
if (typeof a1 === "string") sort = a1;
|
||||||
|
}
|
||||||
|
} else if (args.length >= 3) {
|
||||||
|
const [a0, a1, a2] = args;
|
||||||
|
if (a0 && typeof a0 === "object") {
|
||||||
|
baseVariables = a0;
|
||||||
|
if (typeof a1 === "string") sort = a1;
|
||||||
|
if (typeof a2 === "number") limit = a2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- FIX: Se llama al backend SIN parámetros de orden/límite ---
|
||||||
|
// Se asume que la mayoría de queries 'list' no aceptan variables, solo se pasan si existen.
|
||||||
|
|
||||||
|
//const res = await fn(dataConnect, baseVariables);
|
||||||
|
console.log(`Calling ${ops.list} for ${entityName}`, { variables: baseVariables });
|
||||||
|
const res = await fn(dataConnect, baseVariables);
|
||||||
|
console.log(`Finished ${ops.list} for ${entityName}`, res);
|
||||||
|
|
||||||
|
let items = normalizeResultToArray(res);
|
||||||
|
|
||||||
|
// --- FIX: SE RESTAURA el ordenamiento y límite en el CLIENTE ---
|
||||||
|
// Esto es necesario hasta que el backend pueda manejar estos parámetros.
|
||||||
|
if (sort) {
|
||||||
|
const isDesc = sort.startsWith("-");
|
||||||
|
const field = isDesc ? sort.slice(1) : sort;
|
||||||
|
|
||||||
|
items = items.slice().sort((a, b) => {
|
||||||
|
const av = a?.[field];
|
||||||
|
const bv = b?.[field];
|
||||||
|
|
||||||
|
if (av == null && bv == null) return 0;
|
||||||
|
if (av == null) return 1;
|
||||||
|
if (bv == null) return -1;
|
||||||
|
|
||||||
|
const da = new Date(av);
|
||||||
|
const db = new Date(bv);
|
||||||
|
if (!isNaN(da) && !isNaN(db)) {
|
||||||
|
return isDesc ? db - da : da - db;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (av < bv) return isDesc ? 1 : -1;
|
||||||
|
if (av > bv) return isDesc ? -1 : 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof limit === "number") {
|
||||||
|
items = items.slice(0, limit);
|
||||||
|
}
|
||||||
return items.map(toSnake);
|
return items.map(toSnake);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('list staff failed', err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user