1 import { values } from 'lodash'
2 import * as Sequelize from 'sequelize'
4 import { JOB_STATES } from '../../initializers'
6 import { addMethodsToModel } from '../utils'
13 } from './job-interface'
14 import { JobState } from '../../../shared/models/job.model'
16 let Job: Sequelize.Model<JobInstance, JobAttributes>
17 let listWithLimit: JobMethods.ListWithLimit
19 export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
20 Job = sequelize.define<JobInstance, JobAttributes>('Job',
23 type: DataTypes.ENUM(values(JOB_STATES)),
27 type: DataTypes.STRING,
44 const classMethods = [ listWithLimit ]
45 addMethodsToModel(Job, classMethods)
50 // ---------------------------------------------------------------------------
52 listWithLimit = function (limit: number, state: JobState, callback: JobMethods.ListWithLimitCallback) {
63 return Job.findAll(query).asCallback(callback)