updating important things for the functionality of the front
This commit is contained in:
@@ -373,6 +373,24 @@ const toCamel = (value) => {
|
|||||||
return 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]) => {
|
Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
|
||||||
entitiesModule[entityName] = {
|
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 sort;
|
||||||
let limit;
|
let limit;
|
||||||
let baseVariables; // por si algún list usa variables (como Team)
|
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") {
|
if (entityName !== "Team" && typeof limit === "number") {
|
||||||
items = items.slice(0, limit);
|
items = items.slice(0, limit);
|
||||||
}
|
}
|
||||||
|
//console.log(items)
|
||||||
return 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') {
|
if (!params || typeof params !== 'object') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${entityName}.create expects an object with the fields to insert`
|
`${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 })`);
|
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
|
//update
|
||||||
...(ops.update && {
|
...(ops.update && {
|
||||||
update: async (params) => {
|
update: async (id,params) => {
|
||||||
const fn = dcSdk[ops.update];
|
const fn = dcSdk[ops.update];
|
||||||
if (typeof fn !== 'function') {
|
if (typeof fn !== 'function') {
|
||||||
throw new Error(
|
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) {
|
if (!id) {
|
||||||
throw new Error(`${entityName}.update requires an "id" field`);
|
throw new Error(`${entityName}.update requires an "id" field`);
|
||||||
|
|||||||
Reference in New Issue
Block a user