diff --git a/src/utils.ts b/src/utils.ts index 6db0c83..d9f5c6b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -42,15 +42,15 @@ export const getImporterByFileName = (fileName: string): Importer => { throw new Error('No parser found'); }; -export const postActionHandler = ( - handler: ActionHandler -): ActionHandler => async (request, response, context) => { - if (request.method !== 'post') { - return {}; - } +export const postActionHandler = + (handler: ActionHandler): ActionHandler => + 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; @@ -67,7 +67,17 @@ export const getFileFromRequest = (request: ActionRequest): File => { export const getRecords = async ( context: ActionContext ): Promise => { + 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', + }, }); };