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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user