creation snake_case to camelCase convertor for create and update
This commit is contained in:
@@ -358,6 +358,21 @@ const normalizeResultToArray = (res) => {
|
|||||||
// --- Entities Module ( Data Connect, without REST Base44) ---
|
// --- Entities Module ( Data Connect, without REST Base44) ---
|
||||||
const entitiesModule = {};
|
const entitiesModule = {};
|
||||||
|
|
||||||
|
// --- Helper to convert snake_case to camelCase recursively ---
|
||||||
|
const toCamel = (value) => {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.map(toCamel);
|
||||||
|
}
|
||||||
|
if (value && typeof value === "object") {
|
||||||
|
return Object.entries(value).reduce((acc, [key, val]) => {
|
||||||
|
const camelKey = key.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
||||||
|
acc[camelKey] = toCamel(val);
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
|
Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
|
||||||
entitiesModule[entityName] = {
|
entitiesModule[entityName] = {
|
||||||
|
|
||||||
@@ -510,6 +525,9 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
|
|||||||
payload = params;
|
payload = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//converting to camelCase for data connect
|
||||||
|
payload = toCamel(payload);
|
||||||
|
|
||||||
return fn(dataConnect, payload);
|
return fn(dataConnect, payload);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -560,6 +578,9 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data && typeof data === "object") {
|
||||||
|
data = toCamel(data);
|
||||||
|
}
|
||||||
const vars = { id, ...data };
|
const vars = { id, ...data };
|
||||||
|
|
||||||
return fn(dataConnect, vars);
|
return fn(dataConnect, vars);
|
||||||
|
|||||||
Reference in New Issue
Block a user