1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/lib/services/rest/utils/paginatedResults.ts

14 lines
770 B
TypeScript
Raw Normal View History

2020-11-05 18:58:23 +02:00
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';
2020-11-05 18:58:23 +02:00
2023-10-06 16:03:32 +02:00
export default async function(modelType: number, request: Request, whereQuery: WhereQuery = null, defaultFields: string[] = null): Promise<ModelFeedPage> {
2020-11-05 18:58:23 +02:00
const ModelClass = BaseItem.getClassByItemType(modelType);
2023-10-06 16:03:32 +02:00
const fields = requestFields(request, modelType, defaultFields);
2020-11-05 18:58:23 +02:00
const pagination = requestPaginationOptions(request);
return paginatedFeed(BaseModel.db(), ModelClass.tableName(), pagination, whereQuery, fields);
2020-11-05 18:58:23 +02:00
}