Fix all admin endpoint response formats
Wrap all admin endpoint responses in { data: ... } to match frontend
expectations and project conventions:
- PATCH /users/:id (enable/disable)
- PATCH /users/:id/role (promote/demote)
- GET /users/:id/activity
- GET /activity
- PATCH /settings
This commit is contained in:
@ -164,8 +164,10 @@ router.patch('/users/:id', async (req, res) => {
|
||||
});
|
||||
|
||||
res.json({
|
||||
user: updatedUser,
|
||||
message: isActive ? 'User enabled successfully' : 'User disabled successfully'
|
||||
data: {
|
||||
user: updatedUser,
|
||||
message: isActive ? 'User enabled successfully' : 'User disabled successfully'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating user status:', error);
|
||||
@ -249,8 +251,10 @@ router.patch('/users/:id/role', async (req, res) => {
|
||||
: 'User demoted to user successfully';
|
||||
|
||||
res.json({
|
||||
user: updatedUser,
|
||||
message
|
||||
data: {
|
||||
user: updatedUser,
|
||||
message
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating user role:', error);
|
||||
@ -299,12 +303,14 @@ router.get('/users/:id/activity', async (req, res) => {
|
||||
]);
|
||||
|
||||
res.json({
|
||||
activities,
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
pages: Math.ceil(total / limit) || 0
|
||||
data: {
|
||||
activities,
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
pages: Math.ceil(total / limit) || 0
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
@ -434,12 +440,14 @@ router.get('/activity', async (req, res) => {
|
||||
const activities = await collection.aggregate(pipeline).toArray();
|
||||
|
||||
res.json({
|
||||
activities,
|
||||
pagination: {
|
||||
page: validatedPage,
|
||||
limit: validatedLimit,
|
||||
total,
|
||||
pages: Math.ceil(total / validatedLimit) || 0
|
||||
data: {
|
||||
activities,
|
||||
pagination: {
|
||||
page: validatedPage,
|
||||
limit: validatedLimit,
|
||||
total,
|
||||
pages: Math.ceil(total / validatedLimit) || 0
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
@ -1123,8 +1131,10 @@ router.patch('/settings', async (req, res) => {
|
||||
const updatedSettings = await getSettings(db);
|
||||
|
||||
res.json({
|
||||
settings: updatedSettings,
|
||||
message: 'Settings updated successfully'
|
||||
data: {
|
||||
settings: updatedSettings,
|
||||
message: 'Settings updated successfully'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating settings:', error);
|
||||
|
||||
Reference in New Issue
Block a user