增加cron搜索

This commit is contained in:
whyour
2021-04-04 14:27:09 +08:00
parent f46e20fc81
commit a7d652c86e
3 changed files with 34 additions and 5 deletions
+3 -1
View File
@@ -15,7 +15,9 @@ export default (app: Router) => {
const logger: Logger = Container.get('logger');
try {
const cookieService = Container.get(CronService);
const data = await cookieService.crontabs();
const data = await cookieService.crontabs(
req.query.searchValue as string,
);
return res.send({ code: 200, data });
} catch (e) {
logger.error('🔥 error: %o', e);
+16 -2
View File
@@ -48,10 +48,24 @@ export default class CronService {
await this.set_crontab();
}
public async crontabs(): Promise<Crontab[]> {
public async crontabs(searchText?: string): Promise<Crontab[]> {
let query = {};
if (searchText) {
const reg = new RegExp(searchText);
query = {
$or: [
{
name: reg,
},
{
command: reg,
},
],
};
}
return new Promise((resolve) => {
this.cronDb
.find({})
.find(query)
.sort({ created: -1 })
.exec((err, docs) => {
resolve(docs);