From 0ff8194cf8ec636711a49a5ec8d81d0a357379f2 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Tue, 3 Jan 2023 09:19:07 +0700 Subject: [PATCH] Modify getWorkspaceLogs to accept sortBy query param --- backend/src/ee/controllers/v1/workspaceController.ts | 9 ++++++++- backend/src/ee/routes/v1/workspace.ts | 3 +++ frontend/ee/api/secrets/GetProjectLogs.ts | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/src/ee/controllers/v1/workspaceController.ts b/backend/src/ee/controllers/v1/workspaceController.ts index 4fe040122..25a8c8d76 100644 --- a/backend/src/ee/controllers/v1/workspaceController.ts +++ b/backend/src/ee/controllers/v1/workspaceController.ts @@ -37,6 +37,12 @@ import { }); } +/** + * Return (audit) logs for workspace with id [workspaceId] + * @param req + * @param res + * @returns + */ export const getWorkspaceLogs = async (req: Request, res: Response) => { let logs try { @@ -44,6 +50,7 @@ export const getWorkspaceLogs = async (req: Request, res: Response) => { const offset: number = parseInt(req.query.offset as string); const limit: number = parseInt(req.query.limit as string); + const sortBy: string = req.query.sortBy as string; const userId: string = req.query.userId as string; const actionNames: string = req.query.actionNames as string; @@ -59,7 +66,7 @@ export const getWorkspaceLogs = async (req: Request, res: Response) => { } : {} ) }) - .sort({ createdAt: -1 }) + .sort({ createdAt: sortBy === 'recent' ? -1 : 1 }) .skip(offset) .limit(limit) .populate('actions') diff --git a/backend/src/ee/routes/v1/workspace.ts b/backend/src/ee/routes/v1/workspace.ts index e9e6938bf..5ae190ccd 100644 --- a/backend/src/ee/routes/v1/workspace.ts +++ b/backend/src/ee/routes/v1/workspace.ts @@ -33,6 +33,9 @@ router.get( param('workspaceId').exists().trim(), query('offset').exists().isInt(), query('limit').exists().isInt(), + query('sortBy'), + query('userId'), + query('actionNames'), validateRequest, workspaceController.getWorkspaceLogs ); diff --git a/frontend/ee/api/secrets/GetProjectLogs.ts b/frontend/ee/api/secrets/GetProjectLogs.ts index 277205f2f..e127be815 100644 --- a/frontend/ee/api/secrets/GetProjectLogs.ts +++ b/frontend/ee/api/secrets/GetProjectLogs.ts @@ -25,6 +25,7 @@ const getProjectLogs = async ({ workspaceId, offset, limit, userId, actionNames payload = { offset: String(offset), limit: String(limit), + sortBy: 'recent', userId: JSON.stringify(userId), actionNames: actionNames } @@ -32,18 +33,21 @@ const getProjectLogs = async ({ workspaceId, offset, limit, userId, actionNames payload = { offset: String(offset), limit: String(limit), + sortBy: 'recent', userId: JSON.stringify(userId) } } else if (actionNames != "") { payload = { offset: String(offset), limit: String(limit), + sortBy: 'recent', actionNames: actionNames } } else { payload = { offset: String(offset), - limit: String(limit) + limit: String(limit), + sortBy: 'recent' } }