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 = ({ , - , - ];