- static listForApi (start: number, count: number, sort: SortType) {
- const query = {
- offset: start,
- limit: count,
- order: getSortOnModel(sort.sortModel, sort.sortValue),
- include: [
- {
- model: VideoModel,
- required: true
- }
- ]
+ static listForApi (parameters: {
+ start: number
+ count: number
+ sort: SortType
+ search?: string
+ type?: VideoBlockType
+ }) {
+ const { start, count, sort, search, type } = parameters
+
+ function buildBaseQuery (): FindOptions {
+ return {
+ offset: start,
+ limit: count,
+ order: getBlacklistSort(sort.sortModel, sort.sortValue)
+ }
+ }
+
+ const countQuery = buildBaseQuery()
+
+ const findQuery = buildBaseQuery()
+ findQuery.include = [
+ {
+ model: VideoModel,
+ required: true,
+ where: searchAttribute(search, 'name'),
+ include: [
+ {
+ model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }),
+ required: true
+ },
+ {
+ model: ThumbnailModel,
+ attributes: [ 'type', 'filename' ],
+ required: false
+ }
+ ]
+ }
+ ]
+
+ if (type) {
+ countQuery.where = { type }
+ findQuery.where = { type }