aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/job
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/job')
-rw-r--r--server/models/job/job-interface.ts6
-rw-r--r--server/models/job/job.ts12
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 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird' 2import * as Promise from 'bluebird'
3 3
4import { JobState } from '../../../shared/models/job.model' 4import { JobCategory, JobState } from '../../../shared/models/job.model'
5 5
6export namespace JobMethods { 6export 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
10export interface JobClass { 10export interface JobClass {
11 listWithLimit: JobMethods.ListWithLimit 11 listWithLimitByCategory: JobMethods.ListWithLimitByCategory
12} 12}
13 13
14export interface JobAttributes { 14export 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 @@
1import { values } from 'lodash' 1import { values } from 'lodash'
2import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
3 3
4import { JOB_STATES } from '../../initializers' 4import { JOB_STATES, JOB_CATEGORIES } from '../../initializers'
5 5
6import { addMethodsToModel } from '../utils' 6import { addMethodsToModel } from '../utils'
7import { 7import {
@@ -13,7 +13,7 @@ import {
13import { JobState } from '../../../shared/models/job.model' 13import { JobState } from '../../../shared/models/job.model'
14 14
15let Job: Sequelize.Model<JobInstance, JobAttributes> 15let Job: Sequelize.Model<JobInstance, JobAttributes>
16let listWithLimit: JobMethods.ListWithLimit 16let listWithLimitByCategory: JobMethods.ListWithLimitByCategory
17 17
18export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 18export 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
51listWithLimit = function (limit: number, state: JobState) { 55listWithLimitByCategory = function (limit: number, state: JobState) {
52 const query = { 56 const query = {
53 order: [ 57 order: [
54 [ 'id', 'ASC' ] 58 [ 'id', 'ASC' ]