diff options
Diffstat (limited to 'server/models/job')
-rw-r--r-- | server/models/job/job-interface.ts | 6 | ||||
-rw-r--r-- | server/models/job/job.ts | 12 |
2 files changed, 11 insertions, 7 deletions
diff --git a/server/models/job/job-interface.ts b/server/models/job/job-interface.ts index ba5622977..163930a4f 100644 --- a/server/models/job/job-interface.ts +++ b/server/models/job/job-interface.ts | |||
@@ -1,14 +1,14 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | import { JobState } from '../../../shared/models/job.model' | 4 | import { JobCategory, JobState } from '../../../shared/models/job.model' |
5 | 5 | ||
6 | export namespace JobMethods { | 6 | export namespace JobMethods { |
7 | export type ListWithLimit = (limit: number, state: JobState) => Promise<JobInstance[]> | 7 | export type ListWithLimitByCategory = (limit: number, state: JobState, category: JobCategory) => Promise<JobInstance[]> |
8 | } | 8 | } |
9 | 9 | ||
10 | export interface JobClass { | 10 | export interface JobClass { |
11 | listWithLimit: JobMethods.ListWithLimit | 11 | listWithLimitByCategory: JobMethods.ListWithLimitByCategory |
12 | } | 12 | } |
13 | 13 | ||
14 | export interface JobAttributes { | 14 | export interface JobAttributes { |
diff --git a/server/models/job/job.ts b/server/models/job/job.ts index 968f9d71d..ce1203e5a 100644 --- a/server/models/job/job.ts +++ b/server/models/job/job.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
2 | import * as Sequelize from 'sequelize' | 2 | import * as Sequelize from 'sequelize' |
3 | 3 | ||
4 | import { JOB_STATES } from '../../initializers' | 4 | import { JOB_STATES, JOB_CATEGORIES } from '../../initializers' |
5 | 5 | ||
6 | import { addMethodsToModel } from '../utils' | 6 | import { addMethodsToModel } from '../utils' |
7 | import { | 7 | import { |
@@ -13,7 +13,7 @@ import { | |||
13 | import { JobState } from '../../../shared/models/job.model' | 13 | import { JobState } from '../../../shared/models/job.model' |
14 | 14 | ||
15 | let Job: Sequelize.Model<JobInstance, JobAttributes> | 15 | let Job: Sequelize.Model<JobInstance, JobAttributes> |
16 | let listWithLimit: JobMethods.ListWithLimit | 16 | let listWithLimitByCategory: JobMethods.ListWithLimitByCategory |
17 | 17 | ||
18 | export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 18 | export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
19 | Job = sequelize.define<JobInstance, JobAttributes>('Job', | 19 | Job = sequelize.define<JobInstance, JobAttributes>('Job', |
@@ -22,6 +22,10 @@ export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Se | |||
22 | type: DataTypes.ENUM(values(JOB_STATES)), | 22 | type: DataTypes.ENUM(values(JOB_STATES)), |
23 | allowNull: false | 23 | allowNull: false |
24 | }, | 24 | }, |
25 | category: { | ||
26 | type: DataTypes.ENUM(values(JOB_CATEGORIES)), | ||
27 | allowNull: false | ||
28 | }, | ||
25 | handlerName: { | 29 | handlerName: { |
26 | type: DataTypes.STRING, | 30 | type: DataTypes.STRING, |
27 | allowNull: false | 31 | allowNull: false |
@@ -40,7 +44,7 @@ export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Se | |||
40 | } | 44 | } |
41 | ) | 45 | ) |
42 | 46 | ||
43 | const classMethods = [ listWithLimit ] | 47 | const classMethods = [ listWithLimitByCategory ] |
44 | addMethodsToModel(Job, classMethods) | 48 | addMethodsToModel(Job, classMethods) |
45 | 49 | ||
46 | return Job | 50 | return Job |
@@ -48,7 +52,7 @@ export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Se | |||
48 | 52 | ||
49 | // --------------------------------------------------------------------------- | 53 | // --------------------------------------------------------------------------- |
50 | 54 | ||
51 | listWithLimit = function (limit: number, state: JobState) { | 55 | listWithLimitByCategory = function (limit: number, state: JobState) { |
52 | const query = { | 56 | const query = { |
53 | order: [ | 57 | order: [ |
54 | [ 'id', 'ASC' ] | 58 | [ 'id', 'ASC' ] |