From 2816dcee521ca3c54936307422a28dd721024df2 Mon Sep 17 00:00:00 2001 From: cddjr Date: Mon, 5 Sep 2022 00:04:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D#1611=20?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=E8=A2=AB?= =?UTF-8?q?=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index 50744b3d..fcf11a74 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -115,8 +115,12 @@ export default class CronService { private formatViewQuery(query: any, viewQuery: any) { if (viewQuery.filters && viewQuery.filters.length > 0) { + if (!query[Op.and]) { + query[Op.and] = []; + } for (const col of viewQuery.filters) { const { property, value, operation } = col; + let q: any = {}; let operate = null; switch (operation) { case 'Reg': @@ -126,7 +130,7 @@ export default class CronService { operate = Op.notLike; break; case 'In': - query[Op.or] = [ + q[Op.or] = [ { [property]: value, }, @@ -136,7 +140,7 @@ export default class CronService { ]; break; case 'Nin': - query[Op.and] = [ + q[Op.and] = [ { [property]: { [Op.notIn]: value, @@ -151,19 +155,24 @@ export default class CronService { break; } if (operate) { - query[property] = { + q[property] = { [Op.or]: [ { [operate]: `%${value}%` }, { [operate]: `%${encodeURIComponent(value)}%` }, ], }; } + query[Op.and].push(q); } } } private formatSearchText(query: any, searchText: string | undefined) { if (searchText) { + if (!query[Op.and]) { + query[Op.and] = []; + } + let q: any = {}; const textArray = searchText.split(':'); switch (textArray[0]) { case 'name': @@ -171,7 +180,7 @@ export default class CronService { case 'schedule': case 'label': const column = textArray[0] === 'label' ? 'labels' : textArray[0]; - query[column] = { + q[column] = { [Op.or]: [ { [Op.like]: `%${textArray[1]}%` }, { [Op.like]: `%${encodeURIComponent(textArray[1])}%` }, @@ -185,7 +194,7 @@ export default class CronService { { [Op.like]: `%${encodeURIComponent(searchText)}%` }, ], }; - query[Op.or] = [ + q[Op.or] = [ { name: reg, }, @@ -201,6 +210,7 @@ export default class CronService { ]; break; } + query[Op.and].push(q); } }