From 6fe3687ad348bc72c8ac30244fe4720f240df930 Mon Sep 17 00:00:00 2001 From: APAW Agent Sync Date: Thu, 14 May 2026 09:25:18 +0100 Subject: [PATCH] feat(api): add GET /api/admin/properties endpoint for admin panel Previously admin.js used public /api/properties endpoint which lacks admin-specific fields and returns published_only. New endpoint: - Returns all properties (not just published) - Supports status/type filtering - Returns total count for pagination - Protected by requireAdmin middleware Fixes: admin properties table loading with full dataset. --- src/server/index.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/server/index.ts b/src/server/index.ts index 80088ca..362bace 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -1121,6 +1121,33 @@ app.post('/api/admin/upload', requireAdmin, adminRateLimit, async (c) => { }) // ============ ADMIN PROPERTIES ============ +app.get('/api/admin/properties', requireAdmin, (c) => { + const status = c.req.query('status') || 'active' + const type = c.req.query('type') + const limit = parseInt(c.req.query('limit') || '100') + const offset = parseInt(c.req.query('offset') || '0') + + let query = 'SELECT * FROM properties WHERE status = ?' + const params: any[] = [status] + + if (type) { + query += ' AND type = ?' + params.push(type) + } + + query += ' ORDER BY is_featured DESC, created_at DESC LIMIT ? OFFSET ?' + params.push(limit, offset) + + const properties = db.query(query).all(...params) + const total = (db.query('SELECT COUNT(*) as count FROM properties WHERE status = ?').get(status) as any)?.count || 0 + + return c.json({ + success: true, + data: properties, + total + }) +}) + app.post('/api/admin/properties', requireAdmin, adminRateLimit, async (c) => { try { const body = await c.req.json()