Skip to content
Snippets Groups Projects
Commit 7e81ecb8d2f4 authored by Frank Bessou's avatar Frank Bessou :spider_web:
Browse files

feat: handle sort on getList

parent 6657f8415dcb
No related branches found
No related tags found
1 merge request!4feat: handle sort on getList
......@@ -22,7 +22,8 @@
const httpClient = new client.CwSimpleHttpClient(endpoint, true);
const rqlClient = new client.CwRqlClient(httpClient);
return {
getList: async (resource: ETypesNames<S>, { pagination }) => {
getList: async (resource: ETypesNames<S>, { pagination, sort }) => {
const sortAttribute = sort.field === "id" ? "eid" : sort.field;
const attributesNames = ["eid", ...Object.keys(schema.etypes[resource])];
const selection: string[] = [];
const restrictions: string[] = [];
......@@ -26,7 +27,8 @@
const attributesNames = ["eid", ...Object.keys(schema.etypes[resource])];
const selection: string[] = [];
const restrictions: string[] = [];
let sortvariable = null;
attributesNames.forEach((key, idx) => {
const variable = `X${idx}`;
selection.push(variable);
restrictions.push(`X ${key} ${variable}`);
......@@ -29,10 +31,13 @@
attributesNames.forEach((key, idx) => {
const variable = `X${idx}`;
selection.push(variable);
restrictions.push(`X ${key} ${variable}`);
if (key === sortAttribute) {
sortvariable = variable;
}
});
const total = await rqlClient
.queryRows(`Any Count(${selection[0]}) WHERE ${restrictions.join(",")}`)
.then((rows) => rows[0][0]);
return rqlClient
.queryRows(
......@@ -33,10 +38,12 @@
});
const total = await rqlClient
.queryRows(`Any Count(${selection[0]}) WHERE ${restrictions.join(",")}`)
.then((rows) => rows[0][0]);
return rqlClient
.queryRows(
`Any ${selection.join(", ")} LIMIT ${pagination.perPage} OFFSET ${
`Any ${selection.join(", ")} ORDERBY ${sortvariable} ${
sort.order
} LIMIT ${pagination.perPage} OFFSET ${
pagination.page * pagination.perPage
} WHERE ${restrictions.join(", ")}`,
{}
......
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