]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/application/application.ts
Fix comments deleted display
[github/Chocobozzz/PeerTube.git] / server / models / application / application.ts
CommitLineData
50d6de9c
C
1import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
2import { AccountModel } from '../account/account'
8dc8a34e
C
3import * as memoizee from 'memoizee'
4
5export const getServerActor = memoizee(async function () {
6 const application = await ApplicationModel.load()
7 if (!application) throw Error('Could not load Application from database.')
8
9 const actor = application.Account.Actor
10 actor.Account = application.Account
11
12 return actor
13}, { promise: true })
3fd3ab2d 14
3acc5084 15@DefaultScope(() => ({
50d6de9c
C
16 include: [
17 {
3acc5084 18 model: AccountModel,
50d6de9c
C
19 required: true
20 }
21 ]
3acc5084 22}))
3fd3ab2d 23@Table({
4f0f2ab2
C
24 tableName: 'application',
25 timestamps: false
3fd3ab2d
C
26})
27export class ApplicationModel extends Model<ApplicationModel> {
28
29 @AllowNull(false)
30 @Default(0)
31 @IsInt
32 @Column
33 migrationVersion: number
34
50d6de9c
C
35 @HasOne(() => AccountModel, {
36 foreignKey: {
37 allowNull: true
38 },
39 onDelete: 'cascade'
40 })
41 Account: AccountModel
42
3fd3ab2d
C
43 static countTotal () {
44 return ApplicationModel.count()
45 }
50d6de9c
C
46
47 static load () {
48 return ApplicationModel.findOne()
49 }
00d6b0dd 50}