1 import { values } from 'lodash'
2 import * as Sequelize from 'sequelize'
4 import { JOB_STATES, JOB_CATEGORIES } from '../../initializers'
6 import { addMethodsToModel } from '../utils'
12 } from './job-interface'
13 import { JobState } from '../../../shared/models/job.model'
15 let Job: Sequelize.Model<JobInstance, JobAttributes>
16 let listWithLimitByCategory: JobMethods.ListWithLimitByCategory
18 export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
19 Job = sequelize.define<JobInstance, JobAttributes>('Job',
22 type: DataTypes.ENUM(values(JOB_STATES)),
26 type: DataTypes.ENUM(values(JOB_CATEGORIES)),
30 type: DataTypes.STRING,
47 const classMethods = [ listWithLimitByCategory ]
48 addMethodsToModel(Job, classMethods)
53 // ---------------------------------------------------------------------------
55 listWithLimitByCategory = function (limit: number, state: JobState) {
66 return Job.findAll(query)