From ece40c5e7491ec4d19f8650677a72ed9ae603727 Mon Sep 17 00:00:00 2001 From: nymkappa <1612910616@pm.me> Date: Mon, 11 Mar 2024 19:01:39 +0900 Subject: [PATCH] fix mysql query --- .../src/repositories/AccelerationRepository.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/src/repositories/AccelerationRepository.ts b/backend/src/repositories/AccelerationRepository.ts index a286fca14..c98d007c5 100644 --- a/backend/src/repositories/AccelerationRepository.ts +++ b/backend/src/repositories/AccelerationRepository.ts @@ -70,15 +70,26 @@ class AccelerationRepository { JOIN pools on pools.unique_id = accelerations.pool `; let params: any[] = []; + let hasFilter = false; if (interval) { query += ` WHERE accelerations.added BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW() `; + hasFilter = true; } + if (height != null) { - query += ` WHERE accelerations.height = ? `; + if (hasFilter) { + query += ` AND accelerations.height = ? `; + } else { + query += ` WHERE accelerations.height = ? `; + } params.push(height); } else if (poolSlug != null) { - query += ` WHERE pools.slug = ? `; + if (hasFilter) { + query += ` AND pools.slug = ? `; + } else { + query += ` WHERE pools.slug = ? `; + } params.push(poolSlug); }