mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 20:27:43 +00:00
Modify getWorkspaceLogs to accept sortBy query param
This commit is contained in:
@@ -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) => {
|
export const getWorkspaceLogs = async (req: Request, res: Response) => {
|
||||||
let logs
|
let logs
|
||||||
try {
|
try {
|
||||||
@@ -44,6 +50,7 @@ export const getWorkspaceLogs = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
const offset: number = parseInt(req.query.offset as string);
|
const offset: number = parseInt(req.query.offset as string);
|
||||||
const limit: number = parseInt(req.query.limit 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 userId: string = req.query.userId as string;
|
||||||
const actionNames: string = req.query.actionNames 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)
|
.skip(offset)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.populate('actions')
|
.populate('actions')
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ router.get(
|
|||||||
param('workspaceId').exists().trim(),
|
param('workspaceId').exists().trim(),
|
||||||
query('offset').exists().isInt(),
|
query('offset').exists().isInt(),
|
||||||
query('limit').exists().isInt(),
|
query('limit').exists().isInt(),
|
||||||
|
query('sortBy'),
|
||||||
|
query('userId'),
|
||||||
|
query('actionNames'),
|
||||||
validateRequest,
|
validateRequest,
|
||||||
workspaceController.getWorkspaceLogs
|
workspaceController.getWorkspaceLogs
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ const getProjectLogs = async ({ workspaceId, offset, limit, userId, actionNames
|
|||||||
payload = {
|
payload = {
|
||||||
offset: String(offset),
|
offset: String(offset),
|
||||||
limit: String(limit),
|
limit: String(limit),
|
||||||
|
sortBy: 'recent',
|
||||||
userId: JSON.stringify(userId),
|
userId: JSON.stringify(userId),
|
||||||
actionNames: actionNames
|
actionNames: actionNames
|
||||||
}
|
}
|
||||||
@@ -32,18 +33,21 @@ const getProjectLogs = async ({ workspaceId, offset, limit, userId, actionNames
|
|||||||
payload = {
|
payload = {
|
||||||
offset: String(offset),
|
offset: String(offset),
|
||||||
limit: String(limit),
|
limit: String(limit),
|
||||||
|
sortBy: 'recent',
|
||||||
userId: JSON.stringify(userId)
|
userId: JSON.stringify(userId)
|
||||||
}
|
}
|
||||||
} else if (actionNames != "") {
|
} else if (actionNames != "") {
|
||||||
payload = {
|
payload = {
|
||||||
offset: String(offset),
|
offset: String(offset),
|
||||||
limit: String(limit),
|
limit: String(limit),
|
||||||
|
sortBy: 'recent',
|
||||||
actionNames: actionNames
|
actionNames: actionNames
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
payload = {
|
payload = {
|
||||||
offset: String(offset),
|
offset: String(offset),
|
||||||
limit: String(limit)
|
limit: String(limit),
|
||||||
|
sortBy: 'recent'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user