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({
|
res.json({
|
||||||
|
data: {
|
||||||
user: updatedUser,
|
user: updatedUser,
|
||||||
message: isActive ? 'User enabled successfully' : 'User disabled successfully'
|
message: isActive ? 'User enabled successfully' : 'User disabled successfully'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating user status:', 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';
|
: 'User demoted to user successfully';
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
data: {
|
||||||
user: updatedUser,
|
user: updatedUser,
|
||||||
message
|
message
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating user role:', error);
|
console.error('Error updating user role:', error);
|
||||||
@ -299,6 +303,7 @@ router.get('/users/:id/activity', async (req, res) => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
data: {
|
||||||
activities,
|
activities,
|
||||||
pagination: {
|
pagination: {
|
||||||
page,
|
page,
|
||||||
@ -306,6 +311,7 @@ router.get('/users/:id/activity', async (req, res) => {
|
|||||||
total,
|
total,
|
||||||
pages: Math.ceil(total / limit) || 0
|
pages: Math.ceil(total / limit) || 0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching user activity:', error);
|
console.error('Error fetching user activity:', error);
|
||||||
@ -434,6 +440,7 @@ router.get('/activity', async (req, res) => {
|
|||||||
const activities = await collection.aggregate(pipeline).toArray();
|
const activities = await collection.aggregate(pipeline).toArray();
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
data: {
|
||||||
activities,
|
activities,
|
||||||
pagination: {
|
pagination: {
|
||||||
page: validatedPage,
|
page: validatedPage,
|
||||||
@ -441,6 +448,7 @@ router.get('/activity', async (req, res) => {
|
|||||||
total,
|
total,
|
||||||
pages: Math.ceil(total / validatedLimit) || 0
|
pages: Math.ceil(total / validatedLimit) || 0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching activity:', error);
|
console.error('Error fetching activity:', error);
|
||||||
@ -1123,8 +1131,10 @@ router.patch('/settings', async (req, res) => {
|
|||||||
const updatedSettings = await getSettings(db);
|
const updatedSettings = await getSettings(db);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
data: {
|
||||||
settings: updatedSettings,
|
settings: updatedSettings,
|
||||||
message: 'Settings updated successfully'
|
message: 'Settings updated successfully'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating settings:', error);
|
console.error('Error updating settings:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user