mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-28 15:36:07 +08:00
更新批量增删标签方法
This commit is contained in:
parent
2db02aee41
commit
928f1ce1ee
|
@ -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) => {
|
||||
|
|
|
@ -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<Crontab[]> {
|
||||
|
|
|
@ -151,10 +151,10 @@ const CronLabelModal = ({
|
|||
<Button onClick={() => handleCancel(false)} key="test">
|
||||
取消
|
||||
</Button>,
|
||||
<Button type="primary" danger onClick={() => update('removelabels')}>
|
||||
<Button type="primary" danger onClick={() => update('removeLabels')}>
|
||||
删除
|
||||
</Button>,
|
||||
<Button type="primary" onClick={() => update('addlabels')}>
|
||||
<Button type="primary" onClick={() => update('addLabels')}>
|
||||
添加
|
||||
</Button>
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue
Block a user