1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

Move models to typescript-sequelize

This commit is contained in:
Chocobozzz 2017-12-12 17:53:50 +01:00
parent c893d4514e
commit 3fd3ab2d34
No known key found for this signature in database
GPG key ID: 583A612D890159BE
150 changed files with 3676 additions and 5074 deletions

View file

@ -1,7 +1,9 @@
import { ActivityLike } from '../../../../shared/models/activitypub/activity'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
import { database as db } from '../../../initializers'
import { AccountInstance } from '../../../models/account/account-interface'
import { ActivityLike } from '../../../../shared/models/activitypub'
import { retryTransactionWrapper } from '../../../helpers'
import { sequelizeTypescript } from '../../../initializers'
import { AccountModel } from '../../../models/account/account'
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
import { VideoModel } from '../../../models/video/video'
import { getOrCreateAccountAndServer } from '../account'
import { forwardActivity } from '../send/misc'
@ -19,7 +21,7 @@ export {
// ---------------------------------------------------------------------------
async function processLikeVideo (byAccount: AccountInstance, activity: ActivityLike) {
async function processLikeVideo (byAccount: AccountModel, activity: ActivityLike) {
const options = {
arguments: [ byAccount, activity ],
errorMessage: 'Cannot like the video with many retries.'
@ -28,11 +30,11 @@ async function processLikeVideo (byAccount: AccountInstance, activity: ActivityL
return retryTransactionWrapper(createVideoLike, options)
}
function createVideoLike (byAccount: AccountInstance, activity: ActivityLike) {
function createVideoLike (byAccount: AccountModel, activity: ActivityLike) {
const videoUrl = activity.object
return db.sequelize.transaction(async t => {
const video = await db.Video.loadByUrlAndPopulateAccount(videoUrl)
return sequelizeTypescript.transaction(async t => {
const video = await VideoModel.loadByUrlAndPopulateAccount(videoUrl)
if (!video) throw new Error('Unknown video ' + videoUrl)
@ -41,7 +43,7 @@ function createVideoLike (byAccount: AccountInstance, activity: ActivityLike) {
videoId: video.id,
accountId: byAccount.id
}
const [ , created ] = await db.AccountVideoRate.findOrCreate({
const [ , created ] = await AccountVideoRateModel.findOrCreate({
where: rate,
defaults: rate,
transaction: t