diff --git a/back/services/cron.ts b/back/services/cron.ts index 7e1ff0b2..15f25317 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -12,13 +12,13 @@ import { killTask, } from '../config/util'; import { promises, existsSync } from 'fs'; -import { Op, where, col as colFn } from 'sequelize'; +import { Op, where, col as colFn, FindOptions } from 'sequelize'; import path from 'path'; import { TASK_PREFIX, QL_PREFIX } from '../config/const'; @Service() export default class CronService { - constructor(@Inject('logger') private logger: winston.Logger) {} + constructor(@Inject('logger') private logger: winston.Logger) { } private isSixCron(cron: Crontab) { const { schedule } = cron; @@ -41,7 +41,8 @@ export default class CronService { } public async update(payload: Crontab): Promise { - const tab = new Crontab(payload); + const doc = await this.getDb({ id: payload.id }) + const tab = new Crontab({ ...doc, ...payload }); tab.saved = false; const newDoc = await this.updateDb(tab); await this.set_crontab(); @@ -332,7 +333,7 @@ export default class CronService { } } - public async getDb(query: any): Promise { + public async getDb(query: FindOptions['where']): Promise { const doc: any = await CrontabModel.findOne({ where: { ...query } }); return doc && (doc.get({ plain: true }) as Crontab); } diff --git a/back/services/cronView.ts b/back/services/cronView.ts index 48917ccd..941fe1cb 100644 --- a/back/services/cronView.ts +++ b/back/services/cronView.ts @@ -7,6 +7,7 @@ import { minPosition, stepPosition, } from '../data/env'; +import { FindOptions } from 'sequelize'; @Service() export default class CronViewService { @@ -31,7 +32,9 @@ export default class CronViewService { } public async update(payload: CrontabView): Promise { - const newDoc = await this.updateDb(new CrontabView(payload)); + const doc = await this.getDb({ id: payload.id }) + const tab = new CrontabView({ ...doc, ...payload }); + const newDoc = await this.updateDb(tab); return newDoc; } @@ -56,7 +59,7 @@ export default class CronViewService { } } - public async getDb(query: any): Promise { + public async getDb(query: FindOptions['where']): Promise { const doc: any = await CrontabViewModel.findOne({ where: { ...query } }); return doc && (doc.get({ plain: true }) as CrontabView); } diff --git a/back/services/dependence.ts b/back/services/dependence.ts index 3afee933..c718e687 100644 --- a/back/services/dependence.ts +++ b/back/services/dependence.ts @@ -11,7 +11,7 @@ import { } from '../data/dependence'; import { spawn } from 'child_process'; import SockService from './sock'; -import { Op } from 'sequelize'; +import { FindOptions, Op } from 'sequelize'; import { concurrentRun } from '../config/util'; import dayjs from 'dayjs'; @@ -132,7 +132,7 @@ export default class DependenceService { return docs; } - public async getDb(query: any): Promise { + public async getDb(query: FindOptions['where']): Promise { const doc: any = await DependenceModel.findOne({ where: { ...query } }); return doc && (doc.get({ plain: true }) as Dependence); } diff --git a/back/services/env.ts b/back/services/env.ts index 63b0b74c..8f5015ff 100644 --- a/back/services/env.ts +++ b/back/services/env.ts @@ -12,7 +12,7 @@ import { stepPosition, } from '../data/env'; import groupBy from 'lodash/groupBy'; -import { Op } from 'sequelize'; +import { FindOptions, Op } from 'sequelize'; @Service() export default class EnvService { @@ -49,7 +49,9 @@ export default class EnvService { } public async update(payload: Env): Promise { - const newDoc = await this.updateDb(new Env(payload)); + const doc = await this.getDb({ id: payload.id }) + const tab = new Env({ ...doc, ...payload }); + const newDoc = await this.updateDb(tab); await this.set_envs(); return newDoc; } @@ -162,7 +164,7 @@ export default class EnvService { return docs; } - public async getDb(query: any): Promise { + public async getDb(query: FindOptions['where']): Promise { const doc: any = await EnvModel.findOne({ where: { ...query } }); return doc && (doc.get({ plain: true }) as Env); } diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 421fbeda..c270b088 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -21,7 +21,7 @@ import { killTask, } from '../config/util'; import { promises, existsSync } from 'fs'; -import { Op } from 'sequelize'; +import { FindOptions, Op } from 'sequelize'; import path from 'path'; import ScheduleService, { TaskCallbacks } from './schedule'; import { SimpleIntervalSchedule } from 'toad-scheduler'; @@ -236,7 +236,8 @@ export default class SubscriptionService { } public async update(payload: Subscription): Promise { - const tab = new Subscription(payload); + const doc = await this.getDb({ id: payload.id }) + const tab = new Subscription({ ...doc, ...payload }); const newDoc = await this.updateDb(tab); await this.handleTask(newDoc, !newDoc.is_disabled); await this.setSshConfig(); @@ -288,7 +289,7 @@ export default class SubscriptionService { await this.setSshConfig(); } - public async getDb(query: any): Promise { + public async getDb(query: FindOptions['where']): Promise { const doc: any = await SubscriptionModel.findOne({ where: { ...query } }); return doc && (doc.get({ plain: true }) as Subscription); }