1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/packages/lib/services/rest/utils/paginatedResults.ts
2023-10-06 15:03:32 +01:00

14 lines
770 B
TypeScript

import { Request } from '../Api';
import requestFields from './requestFields';
import BaseModel from '../../../BaseModel';
import requestPaginationOptions from './requestPaginationOptions';
import paginatedFeed, { WhereQuery, ModelFeedPage } from '../../../models/utils/paginatedFeed';
import BaseItem from '../../../models/BaseItem';
export default async function(modelType: number, request: Request, whereQuery: WhereQuery = null, defaultFields: string[] = null): Promise<ModelFeedPage> {
const ModelClass = BaseItem.getClassByItemType(modelType);
const fields = requestFields(request, modelType, defaultFields);
const pagination = requestPaginationOptions(request);
return paginatedFeed(BaseModel.db(), ModelClass.tableName(), pagination, whereQuery, fields);
}