Clean audit log endpoint code

This commit is contained in:
Andrew Kingston 2024-12-05 15:22:18 +00:00
parent 29aa2cc936
commit 42c3a54104
No known key found for this signature in database
1 changed files with 1 additions and 36 deletions

View File

@ -14,48 +14,13 @@ export interface AuditLogEndpoints {
getDownloadUrl: (opts: DownloadAuditLogsRequest) => string getDownloadUrl: (opts: DownloadAuditLogsRequest) => string
} }
const buildOpts = (opts: SearchAuditLogsRequest) => {
const { bookmark, startDate, endDate, fullSearch, events, userIds, appIds } =
opts
const parsedOpts: SearchAuditLogsRequest = {}
if (bookmark) {
parsedOpts.bookmark = bookmark
}
if (opts.startDate && endDate) {
parsedOpts.startDate = startDate
parsedOpts.endDate = endDate
} else if (startDate && !endDate) {
parsedOpts.startDate = startDate
}
if (fullSearch) {
parsedOpts.fullSearch = fullSearch
}
if (events?.length) {
parsedOpts.events = events
}
if (userIds?.length) {
parsedOpts.userIds = userIds
}
if (appIds?.length) {
parsedOpts.appIds = appIds
}
return parsedOpts
}
export const buildAuditLogEndpoints = ( export const buildAuditLogEndpoints = (
API: BaseAPIClient API: BaseAPIClient
): AuditLogEndpoints => ({ ): AuditLogEndpoints => ({
searchAuditLogs: async opts => { searchAuditLogs: async opts => {
return await API.post({ return await API.post({
url: `/api/global/auditlogs/search`, url: `/api/global/auditlogs/search`,
body: buildOpts(opts), body: opts,
}) })
}, },
getEventDefinitions: async () => { getEventDefinitions: async () => {