updating important things for the functionality of the front

This commit is contained in:
José Salazar
2025-12-15 17:22:06 -05:00
parent 6399b5f25a
commit e7546715b2

View File

@@ -373,6 +373,24 @@ const toCamel = (value) => {
return value;
};
// --- Helper to convert camelCase to snake_case recursively ---
const toSnake = (value) => {
if (Array.isArray(value)) {
return value.map(toSnake);
}
if (value && typeof value === "object") {
return Object.entries(value).reduce((acc, [key, val]) => {
const snakeKey = key
.replace(/([A-Z])/g, "_$1")
.toLowerCase();
acc[snakeKey] = toSnake(val);
return acc;
}, {});
}
return value;
};
Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
entitiesModule[entityName] = {
@@ -393,18 +411,6 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
);
}
//return fn(dataConnect);
/*let variables;
const maybeVars = params[0];
if (maybeVars && typeof maybeVars === 'object' && !Array.isArray(maybeVars)) {
variables = maybeVars;
}
const res = await fn(dataConnect, variables);
return normalizeResultToArray(res);
*/
let sort;
let limit;
let baseVariables; // por si algún list usa variables (como Team)
@@ -486,8 +492,9 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
if (entityName !== "Team" && typeof limit === "number") {
items = items.slice(0, limit);
}
return items;
//console.log(items)
//return items;
return items.map(toSnake);
},
}),
@@ -501,14 +508,6 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
);
}
/*const { data } = params ?? {};
if (!data) {
throw new Error(
`${entityName}.create expects a payload like { data: { ...fields } }`
);
}
return fn(dataConnect, data);*/
if (!params || typeof params !== 'object') {
throw new Error(
`${entityName}.create expects an object with the fields to insert`
@@ -546,13 +545,16 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
throw new Error(`${entityName}.get expects an object of variables (e.g. { id })`);
}
return fn(dataConnect, params);
//return fn(dataConnect, params);
const result = await fn(dataConnect, params);
return toSnake(result);
},
}),
//update
...(ops.update && {
update: async (params) => {
update: async (id,params) => {
const fn = dcSdk[ops.update];
if (typeof fn !== 'function') {
throw new Error(
@@ -566,7 +568,8 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
);
}
const { id, data } = params;
//const { id, data } = params;
let data = params;
if (!id) {
throw new Error(`${entityName}.update requires an "id" field`);