diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-22 20:58:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-25 17:32:16 +0200 |
commit | e02643f32e4c97ca307f8fc5b69be79c40d70a3b (patch) | |
tree | b7f6269913cd5a0e4f26a9461a043deb0c168be0 /server/models/job.ts | |
parent | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (diff) | |
download | PeerTube-e02643f32e4c97ca307f8fc5b69be79c40d70a3b.tar.gz PeerTube-e02643f32e4c97ca307f8fc5b69be79c40d70a3b.tar.zst PeerTube-e02643f32e4c97ca307f8fc5b69be79c40d70a3b.zip |
Type models
Diffstat (limited to 'server/models/job.ts')
-rw-r--r-- | server/models/job.ts | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/server/models/job.ts b/server/models/job.ts index 6843e399b..982b51499 100644 --- a/server/models/job.ts +++ b/server/models/job.ts | |||
@@ -1,11 +1,22 @@ | |||
1 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
2 | import * as Sequelize from 'sequelize' | ||
2 | 3 | ||
3 | import { JOB_STATES } from '../initializers' | 4 | import { JOB_STATES } from '../initializers' |
4 | 5 | ||
5 | // --------------------------------------------------------------------------- | 6 | import { addMethodsToModel } from './utils' |
7 | import { | ||
8 | JobClass, | ||
9 | JobInstance, | ||
10 | JobAttributes, | ||
11 | |||
12 | JobMethods | ||
13 | } from './job-interface' | ||
14 | |||
15 | let Job: Sequelize.Model<JobInstance, JobAttributes> | ||
16 | let listWithLimit: JobMethods.ListWithLimit | ||
6 | 17 | ||
7 | module.exports = function (sequelize, DataTypes) { | 18 | export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes) { |
8 | const Job = sequelize.define('Job', | 19 | Job = sequelize.define<JobInstance, JobAttributes>('Job', |
9 | { | 20 | { |
10 | state: { | 21 | state: { |
11 | type: DataTypes.ENUM(values(JOB_STATES)), | 22 | type: DataTypes.ENUM(values(JOB_STATES)), |
@@ -25,19 +36,19 @@ module.exports = function (sequelize, DataTypes) { | |||
25 | { | 36 | { |
26 | fields: [ 'state' ] | 37 | fields: [ 'state' ] |
27 | } | 38 | } |
28 | ], | 39 | ] |
29 | classMethods: { | ||
30 | listWithLimit | ||
31 | } | ||
32 | } | 40 | } |
33 | ) | 41 | ) |
34 | 42 | ||
43 | const classMethods = [ listWithLimit ] | ||
44 | addMethodsToModel(Job, classMethods) | ||
45 | |||
35 | return Job | 46 | return Job |
36 | } | 47 | } |
37 | 48 | ||
38 | // --------------------------------------------------------------------------- | 49 | // --------------------------------------------------------------------------- |
39 | 50 | ||
40 | function listWithLimit (limit, state, callback) { | 51 | listWithLimit = function (limit, state, callback) { |
41 | const query = { | 52 | const query = { |
42 | order: [ | 53 | order: [ |
43 | [ 'id', 'ASC' ] | 54 | [ 'id', 'ASC' ] |
@@ -48,5 +59,5 @@ function listWithLimit (limit, state, callback) { | |||
48 | } | 59 | } |
49 | } | 60 | } |
50 | 61 | ||
51 | return this.findAll(query).asCallback(callback) | 62 | return Job.findAll(query).asCallback(callback) |
52 | } | 63 | } |