Skip to content
Snippets Groups Projects
Commit 8a977db3ceb1 authored by Noé Gaumont's avatar Noé Gaumont :octopus:
Browse files

feat(getOne): retrieve attributes with rqlio

parent ac514970ebfc
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@
const MuseumList = (props: ListProps) => (
<List {...props}>
<Datagrid rowClick="edit">
<Datagrid rowClick="show">
<NumberField source="id" />
<TextField source="name" />
<NumberField source="latitude" />
......
......@@ -60,19 +60,28 @@
};
});
},
getOne: (resource: keyof S["etypes"], _params) => {
return fetch(
`${endpoint}/view?rql=Any+C+LIMIT+1+WHERE+C+is+${resource}+,+C+eid+${_params.id}&vid=ejsonexport`
)
.then((resp) => resp.json())
.then((json) => {
return {
data: json.map((entity: Entity) => ({
...entity,
id: entity.eid,
}))[0],
};
});
getOne: async (resource: ETypesNames<S>, _params) => {
const attributesNames = ["eid", ...Object.keys(schema.etypes[resource])];
const selection: string[] = [];
const restrictions: string[] = [];
attributesNames.forEach((key, idx) => {
const variable = `X${idx}`;
selection.push(variable);
restrictions.push(`X ${key} ${variable}`);
});
const result = await rqlClient.queryRows(
`Any ${selection.join(",")} Where ${restrictions.join(",")}`
);
const row = result[0];
return {
data: row.reduce(
(agg, attributeValue, idx) => ({
[attributesNames[idx]]: attributeValue,
...agg,
}),
{ id: row[0] }
),
};
},
getMany: (_resource, _params) => Promise.reject("Not implemented"),
getManyReference: (_resource, _params) => Promise.reject("Not implemented"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment