From e02643f32e4c97ca307f8fc5b69be79c40d70a3b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 22 May 2017 20:58:25 +0200 Subject: Type models --- server/models/job.ts | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'server/models/job.ts') 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 @@ import { values } from 'lodash' +import * as Sequelize from 'sequelize' import { JOB_STATES } from '../initializers' -// --------------------------------------------------------------------------- +import { addMethodsToModel } from './utils' +import { + JobClass, + JobInstance, + JobAttributes, + + JobMethods +} from './job-interface' + +let Job: Sequelize.Model +let listWithLimit: JobMethods.ListWithLimit -module.exports = function (sequelize, DataTypes) { - const Job = sequelize.define('Job', +export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes) { + Job = sequelize.define('Job', { state: { type: DataTypes.ENUM(values(JOB_STATES)), @@ -25,19 +36,19 @@ module.exports = function (sequelize, DataTypes) { { fields: [ 'state' ] } - ], - classMethods: { - listWithLimit - } + ] } ) + const classMethods = [ listWithLimit ] + addMethodsToModel(Job, classMethods) + return Job } // --------------------------------------------------------------------------- -function listWithLimit (limit, state, callback) { +listWithLimit = function (limit, state, callback) { const query = { order: [ [ 'id', 'ASC' ] @@ -48,5 +59,5 @@ function listWithLimit (limit, state, callback) { } } - return this.findAll(query).asCallback(callback) + return Job.findAll(query).asCallback(callback) } -- cgit v1.2.3