Skip to content

Commit

Permalink
fix: add sortBy to getRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Apr 22, 2022
1 parent 99c430c commit 4a8562c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ export const getFileFromRequest = (request: ActionRequest): File => {
export const getRecords = async (
context: ActionContext
): Promise<BaseRecord[]> => {
const idProperty = context.resource.properties().find((p) => p.isId())?.name?.();
const titleProperty = context.resource.decorate().titleProperty()?.name?.();

return context.resource.find(new Filter({}, context.resource), {
limit: Number.MAX_SAFE_INTEGER,
sort: {
sortBy: idProperty ?? titleProperty,
direction: 'asc',
}
});
};

0 comments on commit 4a8562c

Please sign in to comment.