aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/application
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-05 13:26:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-05 14:14:16 +0200
commit6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch)
tree3365a96d82bc7f00ae504a568725c8e914150cf8 /server/models/application
parent5fe7e898316e18369c3e1aba307b55077adc7bfb (diff)
downloadPeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.gz
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.zst
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.zip
Move to promises
Closes https://github.com/Chocobozzz/PeerTube/issues/74
Diffstat (limited to 'server/models/application')
-rw-r--r--server/models/application/application-interface.ts10
-rw-r--r--server/models/application/application.ts13
2 files changed, 10 insertions, 13 deletions
diff --git a/server/models/application/application-interface.ts b/server/models/application/application-interface.ts
index c03513db1..33254ba2d 100644
--- a/server/models/application/application-interface.ts
+++ b/server/models/application/application-interface.ts
@@ -1,11 +1,13 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
2 3
3export namespace ApplicationMethods { 4export namespace ApplicationMethods {
4 export type LoadMigrationVersionCallback = (err: Error, version: number) => void 5 export type LoadMigrationVersion = () => Promise<number>
5 export type LoadMigrationVersion = (callback: LoadMigrationVersionCallback) => void
6 6
7 export type UpdateMigrationVersionCallback = (err: Error, applicationInstance: ApplicationAttributes) => void 7 export type UpdateMigrationVersion = (
8 export type UpdateMigrationVersion = (newVersion: number, transaction: Sequelize.Transaction, callback: UpdateMigrationVersionCallback) => void 8 newVersion: number,
9 transaction: Sequelize.Transaction
10 ) => Promise<[ number, ApplicationInstance[] ]>
9} 11}
10 12
11export interface ApplicationClass { 13export interface ApplicationClass {
diff --git a/server/models/application/application.ts b/server/models/application/application.ts
index 0e9a1ebb3..507b7a843 100644
--- a/server/models/application/application.ts
+++ b/server/models/application/application.ts
@@ -2,7 +2,6 @@ import * as Sequelize from 'sequelize'
2 2
3import { addMethodsToModel } from '../utils' 3import { addMethodsToModel } from '../utils'
4import { 4import {
5 ApplicationClass,
6 ApplicationAttributes, 5 ApplicationAttributes,
7 ApplicationInstance, 6 ApplicationInstance,
8 7
@@ -35,23 +34,19 @@ export default function defineApplication (sequelize: Sequelize.Sequelize, DataT
35 34
36// --------------------------------------------------------------------------- 35// ---------------------------------------------------------------------------
37 36
38loadMigrationVersion = function (callback: ApplicationMethods.LoadMigrationVersionCallback) { 37loadMigrationVersion = function () {
39 const query = { 38 const query = {
40 attributes: [ 'migrationVersion' ] 39 attributes: [ 'migrationVersion' ]
41 } 40 }
42 41
43 return Application.findOne(query).asCallback(function (err, data) { 42 return Application.findOne(query).then(data => data ? data.migrationVersion : null)
44 const version = data ? data.migrationVersion : null
45
46 return callback(err, version)
47 })
48} 43}
49 44
50updateMigrationVersion = function (newVersion: number, transaction: Sequelize.Transaction, callback: ApplicationMethods.UpdateMigrationVersionCallback) { 45updateMigrationVersion = function (newVersion: number, transaction: Sequelize.Transaction) {
51 const options: Sequelize.UpdateOptions = { 46 const options: Sequelize.UpdateOptions = {
52 where: {}, 47 where: {},
53 transaction: transaction 48 transaction: transaction
54 } 49 }
55 50
56 return Application.update({ migrationVersion: newVersion }, options).asCallback(callback) 51 return Application.update({ migrationVersion: newVersion }, options)
57} 52}