[object Object]

← back to NationalPaperHangers

Coerce a garbage COI project-value to null instead of 500ing the insert

124a38f5ba2eb1bad033e70df5a19de96fdea695 · 2026-05-19 07:57:08 -0700 · Steve

Files touched

Diff

commit 124a38f5ba2eb1bad033e70df5a19de96fdea695
Author: Steve <steve@designerwallcoverings.com>
Date:   Tue May 19 07:57:08 2026 -0700

    Coerce a garbage COI project-value to null instead of 500ing the insert
---
 routes/public.js | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/routes/public.js b/routes/public.js
index 79abbd1..39fff8d 100644
--- a/routes/public.js
+++ b/routes/public.js
@@ -616,7 +616,13 @@ router.post('/installer/:slug/coi-request', express.urlencoded({ extended: false
     const projectAddress        = trim(f.project_address, 400) || null;
     const projectStartDate      = /^\d{4}-\d{2}-\d{2}$/.test(f.project_start_date) ? f.project_start_date : null;
     const projectValueRaw       = String(f.project_value_usd || '').replace(/[^0-9.]/g, '');
-    const projectValueUsd       = projectValueRaw ? Math.min(99999999, Math.max(0, parseFloat(projectValueRaw))) : null;
+    // parseFloat('.') / parseFloat('') are NaN; a bare "." survives the
+    // truthiness check above, so guard explicitly or NaN reaches the NUMERIC
+    // column and 500s the INSERT.
+    const projectValueParsed    = parseFloat(projectValueRaw);
+    const projectValueUsd       = Number.isFinite(projectValueParsed)
+      ? Math.min(99999999, Math.max(0, projectValueParsed))
+      : null;
     const additionalAddress     = trim(f.additional_insured_address, 400) || null;
     const notes                 = trim(f.notes, 800) || null;
 

← 50d107f Reject malformed emails at signup and claim instead of just  ·  back to NationalPaperHangers  ·  Actually limit verified-brand chips to 3 — LIMIT next to arr 1e77ada →