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.
This commit is contained in:
APAW Agent Sync
2026-05-14 09:25:18 +01:00
parent 60a51026cf
commit 6fe3687ad3

View File

@@ -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()