任务视图增加系统视图

This commit is contained in:
whyour
2022-11-26 20:34:07 +08:00
parent 799cda1e3e
commit 1446e925ec
7 changed files with 58 additions and 16 deletions
+6 -2
View File
@@ -58,8 +58,12 @@ export default (app: Router) => {
async (req: Request, res: Response, next: NextFunction) => {
try {
const cronViewService = Container.get(CronViewService);
const data = await cronViewService.update(req.body);
return res.send({ code: 200, data });
if (req.body.type === 1) {
return res.send({ code: 400, message: '参数错误' });
} else {
const data = await cronViewService.update(req.body);
return res.send({ code: 200, data });
}
} catch (e) {
return next(e);
}
+1 -1
View File
@@ -1 +1 @@
export const LOG_END_SYMBOL = '\n          ';
export const LOG_END_SYMBOL = '\n          ';
+8
View File
@@ -1,6 +1,11 @@
import { sequelize } from '.';
import { DataTypes, Model } from 'sequelize';
export enum CronViewType {
'系统' = 1,
'个人',
}
interface SortType {
type: 'ASC' | 'DESC';
value: string;
@@ -20,6 +25,7 @@ export class CrontabView {
filters?: FilterType[];
sorts?: SortType[];
filterRelation?: 'and' | 'or';
type?: CronViewType;
constructor(options: CrontabView) {
this.name = options.name;
@@ -29,6 +35,7 @@ export class CrontabView {
this.filters = options.filters;
this.sorts = options.sorts;
this.filterRelation = options.filterRelation;
this.type = options.type || CronViewType.;
}
}
@@ -50,5 +57,6 @@ export const CrontabViewModel = sequelize.define<CronViewInstance>(
type: DataTypes.STRING,
allowNull: true,
},
type: DataTypes.NUMBER,
},
);
+10 -3
View File
@@ -10,7 +10,7 @@ import { fileExist } from '../config/util';
import { SubscriptionModel } from '../data/subscription';
import { CrontabViewModel } from '../data/cronView';
import config from '../config';
import { sequelize } from '../data'
import { sequelize } from '../data';
export default async () => {
try {
@@ -24,10 +24,17 @@ export default async () => {
// 初始化新增字段
try {
await sequelize.query('alter table CrontabViews add column filterRelation VARCHAR(255)')
await sequelize.query(
'alter table CrontabViews add column filterRelation VARCHAR(255)',
);
} catch (error) {}
try {
await sequelize.query('alter table Subscriptions add column proxy VARCHAR(255)')
await sequelize.query(
'alter table Subscriptions add column proxy VARCHAR(255)',
);
} catch (error) {}
try {
await sequelize.query('alter table CrontabViews add column type NUMBER');
} catch (error) {}
// 2.10-2.11 升级
+16 -1
View File
@@ -8,13 +8,28 @@ import groupBy from 'lodash/groupBy';
import { DependenceModel } from '../data/dependence';
import { Op } from 'sequelize';
import config from '../config';
import { CrontabViewModel } from '../data/cronView';
import { CrontabViewModel, CronViewType } from '../data/cronView';
import { initPosition } from '../data/env';
export default async () => {
const cronService = Container.get(CronService);
const envService = Container.get(EnvService);
const dependenceService = Container.get(DependenceService);
// 初始化新增默认全部任务视图
CrontabViewModel.findAll({
where: { type: CronViewType., name: '全部任务' },
raw: true,
}).then((docs) => {
if (docs.length === 0) {
CrontabViewModel.create({
name: '全部任务',
type: CronViewType.,
position: initPosition / 2,
});
}
});
// 初始化更新所有任务状态为空闲
await CrontabModel.update(
{ status: CrontabStatus.idle },