MVideoPlaylistElementVideoUrlPlaylistPrivacy,
MVideoPlaylistVideoThumbnail
} from '@server/types/models/video/video-playlist-element'
+import { AttributesOnly } from '@shared/typescript-utils'
import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object'
import { VideoPrivacy } from '../../../shared/models/videos'
import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model'
}
]
})
-export class VideoPlaylistElementModel extends Model {
+export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<VideoPlaylistElementModel>>> {
@CreatedAt
createdAt: Date
}
static listUrlsOfForAP (videoPlaylistId: number, start: number, count: number, t?: Transaction) {
- const query = {
- attributes: [ 'url' ],
- offset: start,
- limit: count,
- order: getSort('position'),
- where: {
- videoPlaylistId
- },
- transaction: t
+ const getQuery = (forCount: boolean) => {
+ return {
+ attributes: forCount
+ ? []
+ : [ 'url' ],
+ offset: start,
+ limit: count,
+ order: getSort('position'),
+ where: {
+ videoPlaylistId
+ },
+ transaction: t
+ }
}
- return VideoPlaylistElementModel
- .findAndCountAll(query)
- .then(({ rows, count }) => {
- return { total: count, data: rows.map(e => e.url) }
- })
+ return Promise.all([
+ VideoPlaylistElementModel.count(getQuery(true)),
+ VideoPlaylistElementModel.findAll(getQuery(false))
+ ]).then(([ total, rows ]) => ({
+ total,
+ data: rows.map(e => e.url)
+ }))
}
static loadFirstElementWithVideoThumbnail (videoPlaylistId: number): Promise<MVideoPlaylistVideoThumbnail> {
validate: false // We use a literal to update the position
}
- return VideoPlaylistElementModel.update({ position: Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`) }, query)
+ const positionQuery = Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`)
+ return VideoPlaylistElementModel.update({ position: positionQuery }, query)
}
static increasePositionOf (
videoPlaylistId: number,
fromPosition: number,
- toPosition?: number,
by = 1,
transaction?: Transaction
) {