← back to Commercialrealestate
crcp /api/firm: dedupe current/closed/expired by address+city (DB-path parity with snapshot)
76508c9e3dd4650b09a656226d76a1529a6b1ba6 · 2026-07-31 10:37:47 -0700 · Steve Abrams
Files touched
Diff
commit 76508c9e3dd4650b09a656226d76a1529a6b1ba6
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Fri Jul 31 10:37:47 2026 -0700
crcp /api/firm: dedupe current/closed/expired by address+city (DB-path parity with snapshot)
---
scripts/serve.js | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/scripts/serve.js b/scripts/serve.js
index 89cdbc7..a09efcb 100644
--- a/scripts/serve.js
+++ b/scripts/serve.js
@@ -55,6 +55,9 @@ app.use((req, res, next) => {
return res.status(401).send('Authentication required');
});
+// ── P1 subscription layer: accounts + saved searches + watchlist (docs/TOOL-SPEC.md) ──
+try { require('./crcp-accounts')(app, ROOT); } catch (e) { console.error('[crcp-accounts] mount failed:', e.message); }
+
// ── Agent-contact CRM (durable, local JSON) ─────────────────────────────────────────
// One record per listing id: editable {name,phone,email}, a `contacted_at` stamp, and an
// append-only `letters[]` log (every letter Steve writes to the agent is SAVED here — sending
@@ -898,7 +901,11 @@ app.get('/api/firm', async (req, res) => {
JOIN closed_sale cs ON cs.city = l.city AND split_part(cs.address,' ',1) = split_part(l.address,' ',1)
AND lower(cs.address) LIKE '%'||lower(coalesce((regexp_match(l.address,'[A-Za-z]{3,}'))[1],'~'))||'%'
WHERE b.firm_id=$1 AND cs.sold_price>0 ORDER BY cs.sold_date DESC NULLS LAST LIMIT 40`, [firm.id]).catch(() => []);
- res.json({ firm, roster, agg, current, closed, expired,
+ // Dedupe by address+city — the current UNION ALL across the firm's brokers can list the same
+ // property twice (two agents at the firm on one listing); the snapshot path already dedupes,
+ // so this keeps the DB path at parity.
+ const dedupe = (arr) => { const seen = new Set(); return arr.filter(r => { const k = (r.address || '') + '|' + (r.city || ''); if (seen.has(k)) return false; seen.add(k); return true; }); };
+ res.json({ firm, roster, agg, current: dedupe(current), closed: dedupe(closed), expired: dedupe(expired),
closedNote: closed.length ? null : 'Per-firm closed history needs a gated records source; only enriched pilot brokers carry closings.',
expiredNote: expired.length ? 'Firm listings that now appear in the sold feed (best-effort match — no MLS off-market feed).' : 'No MLS off-market/withdrawn feed matched this firm’s listings.' });
} catch (e) { return snapFirmDetail(res, name); }
← ee6f9c4 CRCP modals: graceful no-coverage state + modal-open telemet
·
back to Commercialrealestate
·
P1 subscription layer: accounts (magic-link) + saved searche 52f46ca →