+ @AfterUpdate
+ static deleteVideoIfFailed (instance: VideoImportModel, options) {
+ if (instance.state === VideoImportState.FAILED) {
+ return afterCommitIfTransaction(options.transaction, () => instance.Video.destroy())
+ }
+
+ return undefined
+ }
+
+ static loadAndPopulateVideo (id: number): Promise<MVideoImportDefault> {
+ return VideoImportModel.findByPk(id)
+ }
+
+ static listUserVideoImportsForApi (userId: number, start: number, count: number, sort: string) {
+ const query = {
+ distinct: true,
+ include: [
+ {
+ attributes: [ 'id' ],
+ model: UserModel.unscoped(), // FIXME: Without this, sequelize try to COUNT(DISTINCT(*)) which is an invalid SQL query
+ required: true
+ }
+ ],
+ offset: start,
+ limit: count,
+ order: getSort(sort),
+ where: {
+ userId
+ }
+ }
+
+ return VideoImportModel.findAndCountAll<MVideoImportDefault>(query)
+ .then(({ rows, count }) => {
+ return {
+ data: rows,
+ total: count
+ }
+ })