Common api - findMany query (#15004)
Done in this PR : - simplify rest input parsing by removing metadata validation (for filter and orderBy - to add in common) (1st commit) - simplify result getter handlers signature (array of objectRecord only for input) closes https://github.com/twentyhq/core-team-issues/issues/1614 closes https://github.com/twentyhq/core-team-issues/issues/1615 closes https://github.com/twentyhq/core-team-issues/issues/1616
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
type ObjectRecord,
|
||||
type ObjectRecordOrderBy,
|
||||
} from 'src/engine/api/graphql/workspace-query-builder/interfaces/object-record.interface';
|
||||
|
||||
import { type CommonPageInfo } from 'src/engine/api/common/types/common-page-info.type';
|
||||
import {
|
||||
encodeCursor,
|
||||
getPaginationInfo,
|
||||
} from 'src/engine/api/graphql/graphql-query-runner/utils/cursors.util';
|
||||
|
||||
export const getPageInfo = (
|
||||
records: ObjectRecord[],
|
||||
orderBy: ObjectRecordOrderBy,
|
||||
limit: number,
|
||||
isForwardPagination: boolean,
|
||||
): CommonPageInfo => {
|
||||
const { hasNextPage, hasPreviousPage } = getPaginationInfo(
|
||||
records,
|
||||
limit,
|
||||
isForwardPagination,
|
||||
);
|
||||
|
||||
const startCursor =
|
||||
records.length > 0 ? encodeCursor(records[0], orderBy) : null;
|
||||
const endCursor =
|
||||
records.length > 0
|
||||
? encodeCursor(records[records.length - 1], orderBy)
|
||||
: null;
|
||||
|
||||
return { startCursor, endCursor, hasNextPage, hasPreviousPage };
|
||||
};
|
||||
Reference in New Issue
Block a user