fix: wire external dogs end-to-end (modal, form flag, pairing simulator) #49
@@ -55,16 +55,33 @@ function attachParents(db, dogs) {
|
|||||||
return 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) => {
|
router.get('/', (req, res) => {
|
||||||
try {
|
try {
|
||||||
const db = getDatabase();
|
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(`
|
const dogs = db.prepare(`
|
||||||
SELECT ${DOG_COLS}
|
SELECT ${DOG_COLS}
|
||||||
FROM dogs
|
FROM dogs
|
||||||
WHERE is_active = 1 AND is_external = 0
|
${whereClause}
|
||||||
ORDER BY name
|
ORDER BY name
|
||||||
`).all();
|
`).all();
|
||||||
|
|
||||||
res.json(attachParents(db, dogs));
|
res.json(attachParents(db, dogs));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching dogs:', error);
|
console.error('Error fetching dogs:', error);
|
||||||
@@ -73,6 +90,7 @@ router.get('/', (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ── GET all dogs (kennel + external) for dropdowns/pairing/pedigree ──────────
|
// ── GET all dogs (kennel + external) for dropdowns/pairing/pedigree ──────────
|
||||||
|
// Kept for backwards-compat; equivalent to GET /?include_external=1
|
||||||
router.get('/all', (req, res) => {
|
router.get('/all', (req, res) => {
|
||||||
try {
|
try {
|
||||||
const db = getDatabase();
|
const db = getDatabase();
|
||||||
@@ -90,6 +108,7 @@ router.get('/all', (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ── GET external dogs only (is_external = 1) ──────────────────────────────
|
// ── GET external dogs only (is_external = 1) ──────────────────────────────
|
||||||
|
// Kept for backwards-compat; equivalent to GET /?external_only=1
|
||||||
router.get('/external', (req, res) => {
|
router.get('/external', (req, res) => {
|
||||||
try {
|
try {
|
||||||
const db = getDatabase();
|
const db = getDatabase();
|
||||||
|
|||||||
Reference in New Issue
Block a user