2020-11-05 18:58:23 +02:00
|
|
|
import { Request } from '../Api';
|
|
|
|
import requestFields from './requestFields';
|
|
|
|
import BaseModel from '../../../BaseModel';
|
|
|
|
import requestPaginationOptions from './requestPaginationOptions';
|
2020-11-11 13:52:47 +02:00
|
|
|
import paginatedFeed, { WhereQuery, ModelFeedPage } from '../../../models/utils/paginatedFeed';
|
2021-01-22 19:41:11 +02:00
|
|
|
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);
|
2020-11-11 13:52:47 +02:00
|
|
|
return paginatedFeed(BaseModel.db(), ModelClass.tableName(), pagination, whereQuery, fields);
|
2020-11-05 18:58:23 +02:00
|
|
|
}
|