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 f2ee916
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ export const getImporterByFileName = (fileName: string): Importer => {
throw new Error('No parser found');
};

export const postActionHandler = (
handler: ActionHandler<ActionResponse>
): ActionHandler<ActionResponse> => async (request, response, context) => {
if (request.method !== 'post') {
return {};
}
export const postActionHandler =
(handler: ActionHandler<ActionResponse>): ActionHandler<ActionResponse> =>
async (request, response, context) => {
if (request.method !== 'post') {
return {};
}

return handler(request, response, context);
};
return handler(request, response, context);
};

export const getFileFromRequest = (request: ActionRequest): File => {
const file = request.payload?.file;
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 f2ee916

Please sign in to comment.