show user history in admin panel

This commit is contained in:
Phillip Thelen
2024-08-28 13:42:19 +02:00
parent 38cad7102f
commit 0bd0ba096b
8 changed files with 292 additions and 7 deletions

View File

@@ -2,6 +2,10 @@ import validator from 'validator';
import { authWithHeaders } from '../../middlewares/auth';
import { ensurePermission } from '../../middlewares/ensureAccessRight';
import { model as User } from '../../models/user';
import { model as UserHistory } from '../../models/userHistory';
import {
NotFound,
} from '../../libs/errors';
const api = {};
@@ -21,7 +25,7 @@ const api = {};
* @apiUse NoUser
* @apiUse NotAdmin
*/
api.getHero = {
api.searchHero = {
method: 'GET',
url: '/admin/search/:userIdentifier',
middlewares: [authWithHeaders(), ensurePermission('userSupport')],
@@ -73,4 +77,43 @@ api.getHero = {
},
};
/**
* @api {get} /api/v4/admin/user/:userId/history Get the history of a user
* @apiParam (Path) {String} userIdentifier The username or email of the user
* @apiName GetUserHistory
* @apiGroup Admin
* @apiPermission Admin
*
* @apiDescription Returns the history of a user
*
* @apiSuccess {Object} data The User history
*
* @apiUse NoAuthHeaders
* @apiUse NoAccount
* @apiUse NoUser
* @apiUse NotAdmin
*/
api.getUserHistory = {
method: 'GET',
url: '/admin/user/:userId/history',
middlewares: [authWithHeaders(), ensurePermission('userSupport')],
async handler (req, res) {
req.checkParams('userId', res.t('heroIdRequired')).notEmpty().isUUID();
const validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
const { userId } = req.params;
const history = await UserHistory
.findOne({ userId })
.lean()
.exec();
if (!history) throw new NotFound(res.t('userWithIDNotFound', { userId }));
res.respond(200, history);
},
};
export default api;