"activate user admin"
This commit is contained in:
@@ -141,32 +141,32 @@ router.get('/users/:userId',
|
||||
});
|
||||
|
||||
// Search users including soft-deleted ones
|
||||
// router.get('/users/search/:searchTerm',
|
||||
// adminRequired,
|
||||
// ValidationMiddleware.validateStringLength({ searchTerm: { min: 2, max: 100 } }),
|
||||
// async (req: Request, res: Response) => {
|
||||
// try {
|
||||
// const { searchTerm } = req.params;
|
||||
// const includeDeleted = req.query.includeDeleted === 'true';
|
||||
router.get('/users/search/:searchTerm',
|
||||
adminRequired,
|
||||
ValidationMiddleware.validateStringLength({ searchTerm: { min: 2, max: 100 } }),
|
||||
async (req: Request, res: Response) => {
|
||||
try {
|
||||
const { searchTerm } = req.params;
|
||||
const includeDeleted = req.query.includeDeleted === 'true';
|
||||
|
||||
// logRequest('Admin search users endpoint accessed', req, res, { searchTerm, includeDeleted });
|
||||
logRequest('Admin search users endpoint accessed', req, res, { searchTerm, includeDeleted });
|
||||
|
||||
// const users = includeDeleted
|
||||
// ? await container.userRepository.searchIncludingDeleted(searchTerm)
|
||||
// : await container.userRepository.search(searchTerm);
|
||||
const users = includeDeleted
|
||||
? await container.userRepository.searchIncludingDeleted(searchTerm)
|
||||
: await container.userRepository.search(searchTerm);
|
||||
|
||||
// logRequest('Admin user search completed', req, res, {
|
||||
// searchTerm,
|
||||
// resultCount: Array.isArray(users) ? users.length : (users.totalCount || 0),
|
||||
// includeDeleted
|
||||
// });
|
||||
logRequest('Admin user search completed', req, res, {
|
||||
searchTerm,
|
||||
resultCount: Array.isArray(users) ? users.length : (users.totalCount || 0),
|
||||
includeDeleted
|
||||
});
|
||||
|
||||
// res.json(users);
|
||||
// } catch (error) {
|
||||
// logError('Admin search users endpoint error', error as Error, req, res);
|
||||
// res.status(500).json({ error: 'Internal server error' });
|
||||
// }
|
||||
// });
|
||||
res.json(users);
|
||||
} catch (error) {
|
||||
logError('Admin search users endpoint error', error as Error, req, res);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
// Update any user (admin only)
|
||||
router.patch('/users/:userId',
|
||||
@@ -213,6 +213,32 @@ router.patch('/users/:userId',
|
||||
}
|
||||
});
|
||||
|
||||
// Activate user (admin only)
|
||||
router.post('/users/:userId/activate',
|
||||
adminRequired,
|
||||
ValidationMiddleware.validateUUIDFormat(['userId']),
|
||||
async (req: Request, res: Response) => {
|
||||
try {
|
||||
const targetUserId = req.params.userId;
|
||||
const adminUserId = (req as any).user.userId;
|
||||
|
||||
logRequest('Admin activate user endpoint accessed', req, res, { adminUserId, targetUserId });
|
||||
|
||||
const result = await container.activateUserCommandHandler.execute({ id: targetUserId });
|
||||
|
||||
if (!result) {
|
||||
return res.status(404).json({ error: 'User not found' });
|
||||
}
|
||||
|
||||
logAuth('User activated by admin', targetUserId, { adminUserId }, req, res);
|
||||
res.json({ message: 'User activated successfully', user: result });
|
||||
|
||||
} catch (error) {
|
||||
logError('Admin activate user endpoint error', error as Error, req, res);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
// Deactivate user (admin only)
|
||||
router.post('/users/:userId/deactivate',
|
||||
adminRequired,
|
||||
|
||||
Reference in New Issue
Block a user