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
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export default async function(modelType: number, request: Request, whereQuery: WhereQuery = null): Promise<ModelFeedPage> {
|
2020-11-05 18:58:23 +02:00
|
|
|
const ModelClass = BaseItem.getClassByItemType(modelType);
|
|
|
|
const fields = requestFields(request, modelType);
|
|
|
|
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
|
|
|
}
|