- static listUserVideoImportsForApi (userId: number, start: number, count: number, sort: string) {
+ static listUserVideoImportsForApi (options: {
+ userId: number
+ start: number
+ count: number
+ sort: string
+
+ search?: string
+ targetUrl?: string
+ videoChannelSyncId?: number
+ }) {
+ const { userId, start, count, sort, targetUrl, videoChannelSyncId, search } = options
+
+ const where: WhereOptions = { userId }
+ const include: IncludeOptions[] = [
+ {
+ attributes: [ 'id' ],
+ model: UserModel.unscoped(), // FIXME: Without this, sequelize try to COUNT(DISTINCT(*)) which is an invalid SQL query
+ required: true
+ },
+ {
+ model: VideoChannelSyncModel.unscoped(),
+ required: false
+ }
+ ]
+
+ if (targetUrl) where['targetUrl'] = targetUrl
+ if (videoChannelSyncId) where['videoChannelSyncId'] = videoChannelSyncId
+
+ if (search) {
+ include.push({
+ model: defaultVideoScope(),
+ required: true,
+ where: searchAttribute(search, 'name')
+ })
+ } else {
+ include.push({
+ model: defaultVideoScope(),
+ required: false
+ })
+ }
+