From 928f1ce1ee6dfc2ad044f4c0b2102dc8ea35f965 Mon Sep 17 00:00:00 2001 From: kilo5hz <1005hz@outlook.com> Date: Fri, 7 Jan 2022 20:18:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=89=B9=E9=87=8F=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=A0=87=E7=AD=BE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/cron.ts | 6 +++--- back/services/cron.ts | 32 ++++++++++++-------------------- src/pages/crontab/modal.tsx | 4 ++-- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/back/api/cron.ts b/back/api/cron.ts index df804ec3..be7cfa4f 100644 --- a/back/api/cron.ts +++ b/back/api/cron.ts @@ -88,7 +88,7 @@ export default (app: Router) => { '/removelabels', celebrate({ body: Joi.object({ - ids:Joi.array().items(Joi.string().required()), + ids:Joi.array().items(Joi.number().required()), labels:Joi.array().items(Joi.string().required()), }) }), @@ -109,7 +109,7 @@ export default (app: Router) => { '/addlabels', celebrate({ body: Joi.object({ - ids:Joi.array().items(Joi.string().required()), + ids:Joi.array().items(Joi.number().required()), labels:Joi.array().items(Joi.string().required()), }) }), @@ -190,7 +190,7 @@ export default (app: Router) => { command: Joi.string().optional(), schedule: Joi.string().optional(), name: Joi.string().optional(), - id: Joi.string().required(), + id: Joi.number().required(), }), }), async (req: Request, res: Response, next: NextFunction) => { diff --git a/back/services/cron.ts b/back/services/cron.ts index 216c0a3a..0c7a7db1 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -94,29 +94,21 @@ export default class CronService { } public async addLabels(ids: string[],labels: string[]){ - return new Promise((resolve: any) => { - this.cronDb.update( - { _id: { $in: ids } }, - { $addToSet: { labels: { $each: labels} } }, - { multi: true }, - async (err) => { - resolve(); - }, - ); - }); + const docs = await CrontabModel.findAll({ where: { id:ids }}); + for (const doc of docs) { + await CrontabModel.update({ + labels: Array.from(new Set(doc.labels.concat(labels))) + },{ where: {id:doc.id}}); + } } public async removeLabels(ids: string[],labels: string[]){ - return new Promise((resolve: any) => { - this.cronDb.update( - { _id: { $in: ids } }, - { $pull: { labels: { $in: labels} } }, - { multi: true }, - async (err) => { - resolve(); - }, - ); - }); + const docs = await CrontabModel.findAll({ where: { id:ids }}); + for (const doc of docs) { + await CrontabModel.update({ + labels: doc.labels.filter( label => !labels.includes(label) ) + },{ where: {id:doc.id}}); + } } public async crontabs(searchText?: string): Promise { diff --git a/src/pages/crontab/modal.tsx b/src/pages/crontab/modal.tsx index bcdad3d8..df0048b5 100644 --- a/src/pages/crontab/modal.tsx +++ b/src/pages/crontab/modal.tsx @@ -151,10 +151,10 @@ const CronLabelModal = ({ , - , - ];