diff options
Diffstat (limited to 'server/models/application')
-rw-r--r-- | server/models/application/application-interface.ts | 9 | ||||
-rw-r--r-- | server/models/application/application.ts | 11 |
2 files changed, 16 insertions, 4 deletions
diff --git a/server/models/application/application-interface.ts b/server/models/application/application-interface.ts index 33254ba2d..2c391dba3 100644 --- a/server/models/application/application-interface.ts +++ b/server/models/application/application-interface.ts | |||
@@ -1,18 +1,21 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import * as Promise from 'bluebird' | 2 | import * as Bluebird from 'bluebird' |
3 | 3 | ||
4 | export namespace ApplicationMethods { | 4 | export namespace ApplicationMethods { |
5 | export type LoadMigrationVersion = () => Promise<number> | 5 | export type LoadMigrationVersion = () => Bluebird<number> |
6 | 6 | ||
7 | export type UpdateMigrationVersion = ( | 7 | export type UpdateMigrationVersion = ( |
8 | newVersion: number, | 8 | newVersion: number, |
9 | transaction: Sequelize.Transaction | 9 | transaction: Sequelize.Transaction |
10 | ) => Promise<[ number, ApplicationInstance[] ]> | 10 | ) => Bluebird<[ number, ApplicationInstance[] ]> |
11 | |||
12 | export type CountTotal = () => Bluebird<number> | ||
11 | } | 13 | } |
12 | 14 | ||
13 | export interface ApplicationClass { | 15 | export interface ApplicationClass { |
14 | loadMigrationVersion: ApplicationMethods.LoadMigrationVersion | 16 | loadMigrationVersion: ApplicationMethods.LoadMigrationVersion |
15 | updateMigrationVersion: ApplicationMethods.UpdateMigrationVersion | 17 | updateMigrationVersion: ApplicationMethods.UpdateMigrationVersion |
18 | countTotal: ApplicationMethods.CountTotal | ||
16 | } | 19 | } |
17 | 20 | ||
18 | export interface ApplicationAttributes { | 21 | export interface ApplicationAttributes { |
diff --git a/server/models/application/application.ts b/server/models/application/application.ts index 507b7a843..8ba40a895 100644 --- a/server/models/application/application.ts +++ b/server/models/application/application.ts | |||
@@ -11,6 +11,7 @@ import { | |||
11 | let Application: Sequelize.Model<ApplicationInstance, ApplicationAttributes> | 11 | let Application: Sequelize.Model<ApplicationInstance, ApplicationAttributes> |
12 | let loadMigrationVersion: ApplicationMethods.LoadMigrationVersion | 12 | let loadMigrationVersion: ApplicationMethods.LoadMigrationVersion |
13 | let updateMigrationVersion: ApplicationMethods.UpdateMigrationVersion | 13 | let updateMigrationVersion: ApplicationMethods.UpdateMigrationVersion |
14 | let countTotal: ApplicationMethods.CountTotal | ||
14 | 15 | ||
15 | export default function defineApplication (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 16 | export default function defineApplication (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
16 | Application = sequelize.define<ApplicationInstance, ApplicationAttributes>('Application', | 17 | Application = sequelize.define<ApplicationInstance, ApplicationAttributes>('Application', |
@@ -26,7 +27,11 @@ export default function defineApplication (sequelize: Sequelize.Sequelize, DataT | |||
26 | } | 27 | } |
27 | ) | 28 | ) |
28 | 29 | ||
29 | const classMethods = [ loadMigrationVersion, updateMigrationVersion ] | 30 | const classMethods = [ |
31 | countTotal, | ||
32 | loadMigrationVersion, | ||
33 | updateMigrationVersion | ||
34 | ] | ||
30 | addMethodsToModel(Application, classMethods) | 35 | addMethodsToModel(Application, classMethods) |
31 | 36 | ||
32 | return Application | 37 | return Application |
@@ -34,6 +39,10 @@ export default function defineApplication (sequelize: Sequelize.Sequelize, DataT | |||
34 | 39 | ||
35 | // --------------------------------------------------------------------------- | 40 | // --------------------------------------------------------------------------- |
36 | 41 | ||
42 | countTotal = function () { | ||
43 | return this.count() | ||
44 | } | ||
45 | |||
37 | loadMigrationVersion = function () { | 46 | loadMigrationVersion = function () { |
38 | const query = { | 47 | const query = { |
39 | attributes: [ 'migrationVersion' ] | 48 | attributes: [ 'migrationVersion' ] |