Add customer search to the support console
Node · Node · advanced · greenfield
Adds the customer-search helper for the support console. Matches the query fragment against name and email with a single ILIKE query through the pg pool, passing the fragment as a bind parameter.
Internal support console behind SSO; the search box accepts free text.
Requirements
- Add searchCustomers(q), the data-access helper behind GET /customers/search, that finds customers by name or email fragment.
- Use the existing pg pool for the query.
- Escape or parameterize any user input that reaches SQL.
- Wildcards (% or _) typed into the search box may broaden the match — that's acceptable for this internal tool.
Files touched
- src/routes/customerSearch.js
--- src/routes/customerSearch.js
+const { pool } = require('../db');
+
+async function searchCustomers(q) {
+ const pattern = `%${q}%`;
+ const result = await pool.query(
+ 'SELECT id, name, email FROM customers WHERE name ILIKE $1 OR email ILIKE $1 LIMIT 25',
+ [pattern]
+ );
+ return result.rows;
+}
+
+module.exports = { searchCustomers };