1 import { values } from 'lodash'
2 import { AllowNull, Column, CreatedAt, DataType, Model, Table, UpdatedAt } from 'sequelize-typescript'
3 import { JobCategory, JobState } from '../../../shared/models'
4 import { JOB_CATEGORIES, JOB_STATES } from '../../initializers'
5 import { getSort } from '../utils'
11 fields: [ 'state', 'category' ]
15 export class JobModel extends Model<JobModel> {
17 @Column(DataType.ENUM(values(JOB_STATES)))
21 @Column(DataType.ENUM(values(JOB_CATEGORIES)))
29 @Column(DataType.JSON)
38 static listWithLimitByCategory (limit: number, state: JobState, jobCategory: JobCategory) {
50 return JobModel.findAll(query)
53 static listForApi (start: number, count: number, sort: string) {
57 order: [ getSort(sort) ]
60 return JobModel.findAndCountAll(query).then(({ rows, count }) => {
72 category: this.category,
73 handlerName: this.handlerName,
74 handlerInputData: this.handlerInputData,
75 createdAt: this.createdAt,
76 updatedAt: this.updatedAt