aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/job.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/job.ts')
-rw-r--r--server/models/job.ts29
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 @@
1import { values } from 'lodash' 1import { values } from 'lodash'
2import * as Sequelize from 'sequelize'
2 3
3import { JOB_STATES } from '../initializers' 4import { JOB_STATES } from '../initializers'
4 5
5// --------------------------------------------------------------------------- 6import { addMethodsToModel } from './utils'
7import {
8 JobClass,
9 JobInstance,
10 JobAttributes,
11
12 JobMethods
13} from './job-interface'
14
15let Job: Sequelize.Model<JobInstance, JobAttributes>
16let listWithLimit: JobMethods.ListWithLimit
6 17
7module.exports = function (sequelize, DataTypes) { 18export 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
40function listWithLimit (limit, state, callback) { 51listWithLimit = 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}