2022-04-01 04:29:09 +08:00
|
|
|
import { defineStore } from 'pinia'
|
2022-04-04 02:54:31 +08:00
|
|
|
import { useApiUtil } from '../composables'
|
2022-04-01 04:29:09 +08:00
|
|
|
|
2022-04-04 02:54:31 +08:00
|
|
|
const { withClientQuery } = useApiUtil()
|
2022-04-01 04:29:09 +08:00
|
|
|
|
|
|
|
import {
|
|
|
|
GET_AUDIT_LOG_FOR_TARGET
|
|
|
|
} from '../graphql/_queries';
|
|
|
|
|
|
|
|
|
2022-04-04 02:54:31 +08:00
|
|
|
export const useAuditLogStore = defineStore('auditlog', {
|
2022-04-01 04:29:09 +08:00
|
|
|
state: () => {
|
|
|
|
return {
|
2022-04-16 03:57:45 +08:00
|
|
|
auditLogs: [] as any as any[],
|
|
|
|
fetchingAudits: false,
|
2022-04-01 04:29:09 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
getters: {
|
|
|
|
getAuditLogs: (state) => state.auditLogs,
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
async fetchAuditLogs(params){
|
2022-04-16 03:57:45 +08:00
|
|
|
this.fetchingAudits = true;
|
2022-04-04 02:54:31 +08:00
|
|
|
await withClientQuery(GET_AUDIT_LOG_FOR_TARGET, params, "auditLogsFilter")
|
2022-04-16 03:57:45 +08:00
|
|
|
.then(payload => {
|
|
|
|
this.fetchingAudits = false
|
2022-08-19 22:40:02 +08:00
|
|
|
this.auditLogs = payload?.map(logs => {
|
|
|
|
logs.stateAfter = typeof logs?.stateAfter === "string" ? JSON.parse(logs?.stateAfter) : logs?.stateAfter
|
|
|
|
logs.stateBefore = typeof logs?.stateBefore === "string" ? JSON.parse(logs?.stateBefore) : logs?.stateBefore
|
2022-04-16 03:57:45 +08:00
|
|
|
return logs
|
2022-08-19 22:40:02 +08:00
|
|
|
})
|
2022-04-16 03:57:45 +08:00
|
|
|
}).catch(err => this.fetchingAudits = false)
|
2022-04-01 04:29:09 +08:00
|
|
|
},
|
2022-08-19 22:40:02 +08:00
|
|
|
async restLogs(){
|
|
|
|
this.auditLogs = [];
|
|
|
|
},
|
2022-04-01 04:29:09 +08:00
|
|
|
}
|
|
|
|
})
|