|
|
@@ -1,6 +1,8 @@
|
|
|
import express, { Request, Router } from 'express';
|
|
|
+import { query } from 'express-validator';
|
|
|
|
|
|
import Crowi from '../../crowi';
|
|
|
+import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
|
|
|
|
|
|
import { ApiV3Response } from './interfaces/apiv3-response';
|
|
|
|
|
|
@@ -9,6 +11,14 @@ interface AuthorizedRequest extends Request {
|
|
|
user?: any
|
|
|
}
|
|
|
|
|
|
+const validator = {
|
|
|
+ list: [
|
|
|
+ query('limit').optional().isInt({ max: 100 }).withMessage('limit must be a number less than or equal to 100'),
|
|
|
+ query('offset').optional().isInt().withMessage('page must be a number'),
|
|
|
+
|
|
|
+ ],
|
|
|
+};
|
|
|
+
|
|
|
module.exports = (crowi: Crowi): Router => {
|
|
|
const adminRequired = require('../../middlewares/admin-required')(crowi);
|
|
|
const accessTokenParser = require('../../middlewares/access-token-parser')(crowi);
|
|
|
@@ -16,9 +26,23 @@ module.exports = (crowi: Crowi): Router => {
|
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
- router.get('/list', accessTokenParser, loginRequiredStrictly, adminRequired, async(req: AuthorizedRequest, res: ApiV3Response) => {
|
|
|
- return res.apiv3({});
|
|
|
- });
|
|
|
+ const activityService = crowi.activityService;
|
|
|
+
|
|
|
+
|
|
|
+ router.get(
|
|
|
+ '/list', accessTokenParser, loginRequiredStrictly, adminRequired, validator.list, apiV3FormValidator, async(req: AuthorizedRequest, res: ApiV3Response) => {
|
|
|
+ const limit = req.query.limit || await crowi.configManager?.getConfig('crowi', 'customize:showPageLimitationS') || 10;
|
|
|
+ const offset = req.query.offset || 1;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const paginatedActivity = await activityService.getPaginatedActivity(limit, offset);
|
|
|
+ return res.apiv3({ paginatedActivity });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ return res.apiv3Err(err);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ );
|
|
|
|
|
|
return router;
|
|
|
};
|