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 39ca177
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const getImporterByFileName = (fileName: string): Importer => {
};

export const postActionHandler = (
handler: ActionHandler<ActionResponse>
handler: ActionHandler<ActionResponse>,
): ActionHandler<ActionResponse> => async (request, response, context) => {
if (request.method !== 'post') {
return {};
Expand All @@ -67,7 +67,17 @@ 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 39ca177

Please sign in to comment.