diff --git a/server/routes/dogs.js b/server/routes/dogs.js index fa601d4..9df96f6 100644 --- a/server/routes/dogs.js +++ b/server/routes/dogs.js @@ -55,16 +55,33 @@ function attachParents(db, dogs) { return dogs; } -// ── GET all kennel dogs (is_external = 0) ─────────────────────────────────── +// ── GET dogs +// Default: kennel dogs only (is_external = 0) +// ?include_external=1 : all active dogs (kennel + external) +// ?external_only=1 : external dogs only +// ───────────────────────────────────────────────────────────────────────── router.get('/', (req, res) => { try { const db = getDatabase(); + const includeExternal = req.query.include_external === '1' || req.query.include_external === 'true'; + const externalOnly = req.query.external_only === '1' || req.query.external_only === 'true'; + + let whereClause; + if (externalOnly) { + whereClause = 'WHERE is_active = 1 AND is_external = 1'; + } else if (includeExternal) { + whereClause = 'WHERE is_active = 1'; + } else { + whereClause = 'WHERE is_active = 1 AND is_external = 0'; + } + const dogs = db.prepare(` SELECT ${DOG_COLS} FROM dogs - WHERE is_active = 1 AND is_external = 0 + ${whereClause} ORDER BY name `).all(); + res.json(attachParents(db, dogs)); } catch (error) { console.error('Error fetching dogs:', error); @@ -73,6 +90,7 @@ router.get('/', (req, res) => { }); // ── GET all dogs (kennel + external) for dropdowns/pairing/pedigree ────────── +// Kept for backwards-compat; equivalent to GET /?include_external=1 router.get('/all', (req, res) => { try { const db = getDatabase(); @@ -90,6 +108,7 @@ router.get('/all', (req, res) => { }); // ── GET external dogs only (is_external = 1) ────────────────────────────── +// Kept for backwards-compat; equivalent to GET /?external_only=1 router.get('/external', (req, res) => { try { const db = getDatabase();