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

Files touched

--- 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 };

Review this PR

Node practice