- return VideoBlacklistModel.findAndCountAll(query)
- .then(({ rows, count }) => {
- return {
- data: rows,
- total: count
- }
- })
+ 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 }
+ }
+
+ return Promise.all([
+ VideoBlacklistModel.count(countQuery),
+ VideoBlacklistModel.findAll(findQuery)
+ ]).then(([ count, rows ]) => {
+ return {
+ data: rows,
+ total: count
+ }
+ })