From 6fcd19ba737f1f5614a56c6925adb882dea43b8d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Jul 2017 13:26:25 +0200 Subject: Move to promises Closes https://github.com/Chocobozzz/PeerTube/issues/74 --- server/models/application/application-interface.ts | 10 ++++++---- server/models/application/application.ts | 13 ++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) (limited to 'server/models/application') 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 @@ import * as Sequelize from 'sequelize' +import * as Promise from 'bluebird' export namespace ApplicationMethods { - export type LoadMigrationVersionCallback = (err: Error, version: number) => void - export type LoadMigrationVersion = (callback: LoadMigrationVersionCallback) => void + export type LoadMigrationVersion = () => Promise - export type UpdateMigrationVersionCallback = (err: Error, applicationInstance: ApplicationAttributes) => void - export type UpdateMigrationVersion = (newVersion: number, transaction: Sequelize.Transaction, callback: UpdateMigrationVersionCallback) => void + export type UpdateMigrationVersion = ( + newVersion: number, + transaction: Sequelize.Transaction + ) => Promise<[ number, ApplicationInstance[] ]> } export 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' import { addMethodsToModel } from '../utils' import { - ApplicationClass, ApplicationAttributes, ApplicationInstance, @@ -35,23 +34,19 @@ export default function defineApplication (sequelize: Sequelize.Sequelize, DataT // --------------------------------------------------------------------------- -loadMigrationVersion = function (callback: ApplicationMethods.LoadMigrationVersionCallback) { +loadMigrationVersion = function () { const query = { attributes: [ 'migrationVersion' ] } - return Application.findOne(query).asCallback(function (err, data) { - const version = data ? data.migrationVersion : null - - return callback(err, version) - }) + return Application.findOne(query).then(data => data ? data.migrationVersion : null) } -updateMigrationVersion = function (newVersion: number, transaction: Sequelize.Transaction, callback: ApplicationMethods.UpdateMigrationVersionCallback) { +updateMigrationVersion = function (newVersion: number, transaction: Sequelize.Transaction) { const options: Sequelize.UpdateOptions = { where: {}, transaction: transaction } - return Application.update({ migrationVersion: newVersion }, options).asCallback(callback) + return Application.update({ migrationVersion: newVersion }, options) } -- cgit v1.2.3