aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/application.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-22 20:58:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-25 17:32:16 +0200
commite02643f32e4c97ca307f8fc5b69be79c40d70a3b (patch)
treeb7f6269913cd5a0e4f26a9461a043deb0c168be0 /server/models/application.ts
parent65fcc3119c334b75dd13bcfdebf186afdc580a8f (diff)
downloadPeerTube-e02643f32e4c97ca307f8fc5b69be79c40d70a3b.tar.gz
PeerTube-e02643f32e4c97ca307f8fc5b69be79c40d70a3b.tar.zst
PeerTube-e02643f32e4c97ca307f8fc5b69be79c40d70a3b.zip
Type models
Diffstat (limited to 'server/models/application.ts')
-rw-r--r--server/models/application.ts38
1 files changed, 25 insertions, 13 deletions
diff --git a/server/models/application.ts b/server/models/application.ts
index 38a57e327..acd0dfbf2 100644
--- a/server/models/application.ts
+++ b/server/models/application.ts
@@ -1,5 +1,20 @@
1module.exports = function (sequelize, DataTypes) { 1import * as Sequelize from 'sequelize'
2 const Application = sequelize.define('Application', 2
3import { addMethodsToModel } from './utils'
4import {
5 ApplicationClass,
6 ApplicationAttributes,
7 ApplicationInstance,
8
9 ApplicationMethods
10} from './application-interface'
11
12let Application: Sequelize.Model<ApplicationInstance, ApplicationAttributes>
13let loadMigrationVersion: ApplicationMethods.LoadMigrationVersion
14let updateMigrationVersion: ApplicationMethods.UpdateMigrationVersion
15
16export default function defineApplication (sequelize: Sequelize.Sequelize, DataTypes) {
17 Application = sequelize.define<ApplicationInstance, ApplicationAttributes>('Application',
3 { 18 {
4 migrationVersion: { 19 migrationVersion: {
5 type: DataTypes.INTEGER, 20 type: DataTypes.INTEGER,
@@ -9,34 +24,31 @@ module.exports = function (sequelize, DataTypes) {
9 isInt: true 24 isInt: true
10 } 25 }
11 } 26 }
12 },
13 {
14 classMethods: {
15 loadMigrationVersion,
16 updateMigrationVersion
17 }
18 } 27 }
19 ) 28 )
20 29
30 const classMethods = [ loadMigrationVersion, updateMigrationVersion ]
31 addMethodsToModel(Application, classMethods)
32
21 return Application 33 return Application
22} 34}
23 35
24// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
25 37
26function loadMigrationVersion (callback) { 38loadMigrationVersion = function (callback: (err: Error, version: number) => void) {
27 const query = { 39 const query = {
28 attributes: [ 'migrationVersion' ] 40 attributes: [ 'migrationVersion' ]
29 } 41 }
30 42
31 return this.findOne(query).asCallback(function (err, data) { 43 return Application.findOne(query).asCallback(function (err, data) {
32 const version = data ? data.migrationVersion : null 44 const version = data ? data.migrationVersion : null
33 45
34 return callback(err, version) 46 return callback(err, version)
35 }) 47 })
36} 48}
37 49
38function updateMigrationVersion (newVersion, transaction, callback) { 50updateMigrationVersion = function (newVersion: number, transaction: any, callback: any) {
39 const options: { where?: any, transaction?: any } = { 51 const options: Sequelize.UpdateOptions = {
40 where: {} 52 where: {}
41 } 53 }
42 54
@@ -46,5 +58,5 @@ function updateMigrationVersion (newVersion, transaction, callback) {
46 options.transaction = transaction 58 options.transaction = transaction
47 } 59 }
48 60
49 return this.update({ migrationVersion: newVersion }, options).asCallback(callback) 61 return Application.update({ migrationVersion: newVersion }, options).asCallback(callback)
50} 62}