Skip to content

Commit c359f59

Browse files
committed
fix: make filters and sort optional in resource data request schema and handling logic
1 parent 1205b9d commit c359f59

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

adminforth/modules/restApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function createErrorOrSuccessSchema(successSchema: AnySchemaObject): AnySchemaOb
277277
const getResourceDataRequestSchema: AnySchemaObject = {
278278
type: 'object',
279279
$defs: commonFilterSchemaDefs,
280-
required: ['resourceId', 'source', 'limit', 'offset', 'filters', 'sort'],
280+
required: ['resourceId', 'source', 'limit', 'offset'],
281281
properties: {
282282
resourceId: { type: 'string' },
283283
source: {
@@ -1330,7 +1330,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
13301330
}
13311331

13321332
const meta = { requestBody: body, pk: undefined };
1333-
if (source === 'edit' || source === 'show') {
1333+
if ((source === 'edit' || source === 'show') && body.filters) {
13341334
meta.pk = body.filters.find((f) => f.field === resource.columns.find((col) => col.primaryKey).name)?.value;
13351335
}
13361336

@@ -1420,7 +1420,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
14201420
: undefined;
14211421

14221422
// remove virtual fields from sort if still presented after beforeDatasourceRequest hook
1423-
const sortFiltered = sort.filter((sortItem: IAdminForthSort) => {
1423+
const sortFiltered = (sort || []).filter((sortItem: IAdminForthSort) => {
14241424
return !resource.columns.find((col) => col.name === sortItem.field && col.virtual);
14251425
});
14261426

0 commit comments

Comments
 (0)